☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Providing custom labels (xticks) to line()

Community Support
Clint_Olsen
Clint_Olsen

We are trying to experiment with bokeh coming from a Pandas & matplotlib environment. One of the things that’s missing is plotting series data with an x-axis which is an alphanumeric set of labels.

I don’t know what this is called in bokeh terminology, but matplotlib allows you set every xtick label explicitly like:

plt.xticks(range(len(xticks)), xticks)

Where xticks = [‘a’,‘b’,‘c’]…

The best analogous feature I could find was a FuncTickFormatter, but this requires you to provide JS (or Python) to perform the same function. Unfortunately, the example on the web shows you referring to a ‘tick’ parameter and there’s no apparent way to pass in data to this function, so I don’t have an easy way to accomplish this.

FYI, we are on bokeh 0.12.10 which is tied to the particular Anaconda release we have.

Thanks,

-Clint

⌁   Link to post
Bryan
Bryan

Hi,

You question is a bit underspecified, it sounds like you have a continuous numeric axis (not a categorical axis), but that you want to label fixed positions in a custom way?

Then you can set .ticker on the axis to specify fixed tick positions:

  bokeh.models.axes — Bokeh 0.12.10 documentation

And you can set .major_label_overrides on the axis to map those fixed positions to arbitrary labels:
  
  bokeh.models.axes — Bokeh 0.12.10 documentation

Something like:

  p.xaxis.ticker = [ 1, 5, 10 ]
  p.xaxis.major_label_overrides = { 1: 'a', 5: 'b', 10: 'c' }

If you have actual categorical data and axes, you should refer to this chapter of the users guide:

  Handling Categorical Data — Bokeh 0.12.10 documentation

Thanks,

Bryan

···

On Jul 25, 2018, at 15:04, Clint Olsen <clint.olsen@gmail.com> wrote:

We are trying to experiment with bokeh coming from a Pandas & matplotlib environment. One of the things that's missing is plotting series data with an x-axis which is an alphanumeric set of labels.

I don't know what this is called in bokeh terminology, but matplotlib allows you set every xtick label explicitly like:

plt.xticks(range(len(xticks)), xticks)

Where xticks = ['a','b','c']...

The best analogous feature I could find was a FuncTickFormatter, but this requires you to provide JS (or Python) to perform the same function. Unfortunately, the example on the web shows you referring to a 'tick' parameter and there's no apparent way to pass in data to this function, so I don't have an easy way to accomplish this.

FYI, we are on bokeh 0.12.10 which is tied to the particular Anaconda release we have.

Thanks,

-Clint

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+unsubscribe@continuum.io.
To post to this group, send email to bokeh@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/df24b1e5-d438-4d06-bcfd-b6c705acec12%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

⌁   Link to post
Clint_Olsen
Clint_Olsen

Hi:

I tried your change, and it works well. I used:

p.xaxis.major_label_overrides = dict(zip(range(len(xticks)), xticks))

p.xaxis.major_label_orientation = ‘vertical’

p.xaxis.ticker = list(range(len(xticks)))

Yes, this is categorical data. However, we like to use line plots so we can superimpose the results on the same chart. Bar charts don’t lend themselves as well to have many independent trials. You can think of the plots as connecting the tops of the bars to produce a behavioral curve.

Thanks,

-Clint

···

On Wednesday, July 25, 2018 at 3:15:51 PM UTC-7, Bryan Van de ven wrote:

Hi,

You question is a bit underspecified, it sounds like you have a continuous numeric axis (not a categorical axis), but that you want to label fixed positions in a custom way?

Then you can set .ticker on the axis to specify fixed tick positions:

    [https://bokeh.pydata.org/en/0.12.10/docs/reference/models/axes.html#bokeh.models.axes.Axis.ticker](https://bokeh.pydata.org/en/0.12.10/docs/reference/models/axes.html#bokeh.models.axes.Axis.ticker)

And you can set .major_label_overrides on the axis to map those fixed positions to arbitrary labels:

    [https://bokeh.pydata.org/en/0.12.10/docs/reference/models/axes.html#bokeh.models.axes.Axis.major_label_overrides](https://bokeh.pydata.org/en/0.12.10/docs/reference/models/axes.html#bokeh.models.axes.Axis.major_label_overrides)

Something like:

    p.xaxis.ticker = [ 1, 5, 10 ]

    p.xaxis.major_label_overrides = { 1: 'a', 5: 'b', 10: 'c' }

If you have actual categorical data and axes, you should refer to this chapter of the users guide:

    [https://bokeh.pydata.org/en/0.12.10/docs/user_guide/categorical.html](https://bokeh.pydata.org/en/0.12.10/docs/user_guide/categorical.html)

Thanks,

Bryan

On Jul 25, 2018, at 15:04, Clint Olsen clint...@gmail.com wrote:

We are trying to experiment with bokeh coming from a Pandas & matplotlib environment. One of the things that’s missing is plotting series data with an x-axis which is an alphanumeric set of labels.

I don’t know what this is called in bokeh terminology, but matplotlib allows you set every xtick label explicitly like:

plt.xticks(range(len(xticks)), xticks)

Where xticks = [‘a’,‘b’,‘c’]…

The best analogous feature I could find was a FuncTickFormatter, but this requires you to provide JS (or Python) to perform the same function. Unfortunately, the example on the web shows you referring to a ‘tick’ parameter and there’s no apparent way to pass in data to this function, so I don’t have an easy way to accomplish this.

FYI, we are on bokeh 0.12.10 which is tied to the particular Anaconda release we have.

Thanks,

-Clint

–
You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.

To post to this group, send email to bo...@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/df24b1e5-d438-4d06-bcfd-b6c705acec12%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

⌁   Link to post
Bryan
Bryan

Just to be clear, categorical factors in Bokeh are always strings, and a true categorical axis in Bokeh does not have the .ticker attribute all. I would describe your approach more or less as "faking" a categorial axis, not in pejorative way, but merely to be clear that the underlying axis and coordinates you are using are continuous numerical ones.

Thanks,

Bryan

···

On Jul 25, 2018, at 15:38, Clint Olsen <clint.olsen@gmail.com> wrote:

Hi:

I tried your change, and it works well. I used:

    p.xaxis.major_label_overrides = dict(zip(range(len(xticks)), xticks))
    p.xaxis.major_label_orientation = 'vertical'
    p.xaxis.ticker = list(range(len(xticks)))

Yes, this is categorical data. However, we like to use line plots so we can superimpose the results on the same chart. Bar charts don't lend themselves as well to have many independent trials. You can think of the plots as connecting the tops of the bars to produce a behavioral curve.

Thanks,

-Clint

On Wednesday, July 25, 2018 at 3:15:51 PM UTC-7, Bryan Van de ven wrote:
Hi,

You question is a bit underspecified, it sounds like you have a continuous numeric axis (not a categorical axis), but that you want to label fixed positions in a custom way?

Then you can set .ticker on the axis to specify fixed tick positions:

        bokeh.models.axes — Bokeh 0.12.10 documentation

And you can set .major_label_overrides on the axis to map those fixed positions to arbitrary labels:
         
        bokeh.models.axes — Bokeh 0.12.10 documentation

Something like:

        p.xaxis.ticker = [ 1, 5, 10 ]
        p.xaxis.major_label_overrides = { 1: 'a', 5: 'b', 10: 'c' }

If you have actual categorical data and axes, you should refer to this chapter of the users guide:

        Handling Categorical Data — Bokeh 0.12.10 documentation

Thanks,

Bryan
         
> On Jul 25, 2018, at 15:04, Clint Olsen <clint...@gmail.com> wrote:
>
> We are trying to experiment with bokeh coming from a Pandas & matplotlib environment. One of the things that's missing is plotting series data with an x-axis which is an alphanumeric set of labels.
>
> I don't know what this is called in bokeh terminology, but matplotlib allows you set every xtick label explicitly like:
>
> plt.xticks(range(len(xticks)), xticks)
>
> Where xticks = ['a','b','c']...
>
> The best analogous feature I could find was a FuncTickFormatter, but this requires you to provide JS (or Python) to perform the same function. Unfortunately, the example on the web shows you referring to a 'tick' parameter and there's no apparent way to pass in data to this function, so I don't have an easy way to accomplish this.
>
> FYI, we are on bokeh 0.12.10 which is tied to the particular Anaconda release we have.
>
> Thanks,
>
> -Clint
>
> --
> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.
> To post to this group, send email to bo...@continuum.io.
> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/df24b1e5-d438-4d06-bcfd-b6c705acec12%40continuum.io\.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+unsubscribe@continuum.io.
To post to this group, send email to bokeh@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/5ac45e22-cce2-4d7d-9e7b-3793680efd66%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

⌁   Link to post

End of archived discussion · Replies are disabled