☰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

controlling format of axis labels for datetime axis

Community Support
Jonathan_Slavin
Jonathan_Slavin

Hi,

I’ve been plotting data where the x values are datetime objects. Using the x_axis_type = ‘datetime’ argument to figure, that axis is labeled correctly but with a very short format: hh:mm (where hh is the hour and mm is the minutes). I’d like to have a longer string used for the date which would include the month and day, even though it is redundant (i.e. every point will have the same month and day in most cases). How do I do that? I was looking at the methods and attributes of the axis and nothing jumped out at me.

Thanks,

Jon

⌁   Link to post
Bryan
Bryan

Hi,

When you specify "datetime" then your axis gets configured with a DatetimeTickFormatter, which can be accessed by, e.g.

  plot.xaxis.formatter

The different scales for DatetimeTickFormatter can be configured at a fine level:

  formatters — Bokeh 3.3.2 Documentation

However, I notice that there is nothing about this in the users guide. It would be good to add something about this there as well. I'd encourage you to open a GitHub issue for this (and also submit a PR if you are able).

Thanks,

Bryan

···

On Apr 10, 2017, at 13:35, Jonathan Slavin <jslavin@cfa.harvard.edu> wrote:

Hi,

I've been plotting data where the x values are datetime objects. Using the x_axis_type = 'datetime' argument to figure, that axis is labeled correctly but with a very short format: hh:mm (where hh is the hour and mm is the minutes). I'd like to have a longer string used for the date which would include the month and day, even though it is redundant (i.e. every point will have the same month and day in most cases). How do I do that? I was looking at the methods and attributes of the axis and nothing jumped out at me.

Thanks,
Jon

--
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/bb7be028-787c-43de-8d03-a0ab4d02316c%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

⌁   Link to post
Jonathan_Slavin
Jonathan_Slavin

Hi Bryan,

Thanks for your response. I was looking at that page and having a hard time figuring out what was going wrong with my attempts to set the values of some attributes. I discovered that I had an older version of bokeh installed and the class definition of the DatetimeTickFormatter has changed substantially. After updating, I can now set the attributes (.e.g hourmin) as I wanted.

This has led me to another issue, however. In maplotlib the datetime tick labels that are too long can be made to angle diagonally so that they don’t overlap. Can that be done with bokeh?

Regards,

Jon

···

On Tue, Apr 11, 2017 at 12:43 PM, Bryan Van de ven bryanv@continuum.io wrote:

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

Hi,

When you specify “datetime” then your axis gets configured with a DatetimeTickFormatter, which can be accessed by, e.g.

    plot.xaxis.formatter

The different scales for DatetimeTickFormatter can be configured at a fine level:

    [http://bokeh.pydata.org/en/latest/docs/reference/models/formatters.html#bokeh.models.formatters.DatetimeTickFormatter](http://bokeh.pydata.org/en/latest/docs/reference/models/formatters.html#bokeh.models.formatters.DatetimeTickFormatter)

However, I notice that there is nothing about this in the users guide. It would be good to add something about this there as well. I’d encourage you to open a GitHub issue for this (and also submit a PR if you are able).

Thanks,

Bryan

On Apr 10, 2017, at 13:35, Jonathan Slavin jslavin@cfa.harvard.edu wrote:

Hi,

I’ve been plotting data where the x values are datetime objects. Using the x_axis_type = ‘datetime’ argument to figure, that axis is labeled correctly but with a very short format: hh:mm (where hh is the hour and mm is the minutes). I’d like to have a longer string used for the date which would include the month and day, even though it is redundant (i.e. every point will have the same month and day in most cases). How do I do that? I was looking at the methods and attributes of the axis and nothing jumped out at me.

Thanks,

Jon

–

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/bb7be028-787c-43de-8d03-a0ab4d02316c%40continuum.io.

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

–

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

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/ym0BQDeiccQ/unsubscribe.

To unsubscribe from this group and all its topics, 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/3B34D270-E4E4-4EDF-B43C-C7606F9900FE%40continuum.io.

–


Jonathan D. Slavin Harvard-Smithsonian CfA
jslavin@cfa.harvard.edu 60 Garden Street, MS 83
phone: (617) 496-7981 Cambridge, MA 02138-1516
cell: (781) 363-0035 USA


⌁   Link to post
Bryan
Bryan

Hi Bryan,

Thanks for your response. I was looking at that page and having a hard time figuring out what was going wrong with my attempts to set the values of some attributes. I discovered that I had an older version of bokeh installed and the class definition of the DatetimeTickFormatter has changed substantially. After updating, I can now set the attributes (.e.g hourmin) as I wanted.

Yes it's been changed for quite a white now. The old version was too easy to misconfigure in ways that caused hard to diagnose errors.

This has led me to another issue, however. In maplotlib the datetime tick labels that are too long can be made to angle diagonally so that they don't overlap. Can that be done with bokeh?

That's a property of the axis:

  Appearance — Bokeh 3.3.2 Documentation

Thanks,

Bryan

···

On Apr 11, 2017, at 13:25, Slavin, Jonathan <jslavin@cfa.harvard.edu> wrote:

Regards,
Jon

On Tue, Apr 11, 2017 at 12:43 PM, Bryan Van de ven <bryan@bokeh.org> wrote:
Hi,

When you specify "datetime" then your axis gets configured with a DatetimeTickFormatter, which can be accessed by, e.g.

        plot.xaxis.formatter

The different scales for DatetimeTickFormatter can be configured at a fine level:

        formatters — Bokeh 3.3.2 Documentation

However, I notice that there is nothing about this in the users guide. It would be good to add something about this there as well. I'd encourage you to open a GitHub issue for this (and also submit a PR if you are able).

Thanks,

Bryan

> On Apr 10, 2017, at 13:35, Jonathan Slavin <jslavin@cfa.harvard.edu> wrote:
>
> Hi,
>
> I've been plotting data where the x values are datetime objects. Using the x_axis_type = 'datetime' argument to figure, that axis is labeled correctly but with a very short format: hh:mm (where hh is the hour and mm is the minutes). I'd like to have a longer string used for the date which would include the month and day, even though it is redundant (i.e. every point will have the same month and day in most cases). How do I do that? I was looking at the methods and attributes of the axis and nothing jumped out at me.
>
> Thanks,
> Jon
>
> --
> 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/bb7be028-787c-43de-8d03-a0ab4d02316c%40continuum.io\.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to a topic in the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/ym0BQDeiccQ/unsubscribe\.
To unsubscribe from this group and all its topics, 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/3B34D270-E4E4-4EDF-B43C-C7606F9900FE%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
________________________________________________________
Jonathan D. Slavin Harvard-Smithsonian CfA
jslavin@cfa.harvard.edu 60 Garden Street, MS 83
phone: (617) 496-7981 Cambridge, MA 02138-1516
cell: (781) 363-0035 USA
________________________________________________________

--
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/CACcRS%3De%3D_DO9QU-LxGbCjXiwjKDBBwfYZ2B3JeV1H%3DfTMtisFg%40mail.gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

⌁   Link to post
Jonathan_Slavin
Jonathan_Slavin

​Thanks for the pointer to how to change label orientation. I should be all
set now.​

···

On Tue, Apr 11, 2017 at 3:27 PM, Bryan Van de ven <bryan@bokeh.org> wrote:

> On Apr 11, 2017, at 13:25, Slavin, Jonathan <jslavin@cfa.harvard.edu> > wrote:
>
> Hi Bryan,
>
> Thanks for your response. I was looking at that page and having a hard
time figuring out what was going wrong with my attempts to set the values
of some attributes. I discovered that I had an older version of bokeh
installed and the class definition of the DatetimeTickFormatter has changed
substantially. After updating, I can now set the attributes (.e.g hourmin)
as I wanted.

Yes it's been changed for quite a white now. The old version was too easy
to misconfigure in ways that caused hard to diagnose errors.

> This has led me to another issue, however. In maplotlib the datetime
tick labels that are too long can be made to angle diagonally so that they
don't overlap. Can that be done with bokeh?

That's a property of the axis:

        http://bokeh.pydata.org/en/latest/docs/user_guide/
styling.html#tick-label-orientation

Thanks,

Bryan

--
________________________________________________________
Jonathan D. Slavin Harvard-Smithsonian CfA
jslavin@cfa.harvard.edu 60 Garden Street, MS 83
phone: (617) 496-7981 Cambridge, MA 02138-1516
cell: (781) 363-0035 USA
________________________________________________________

⌁   Link to post
Chris_Withers
Chris_Withers

From the docs: “By default, only the first format string passed for each time scale will be used” - what is the second format there for and how do I get it to be used? (the second item in all the default lists looks to be what I want!)

⌁   Link to post
Bryan
Bryan

@Chris_Withers please prefer making new topics over necro-bumping four year old ones.

I don’t actually think additional formats are ever used. The datetime ticker formatters took inspiration from another plotting system we had worked on years prior that does use multiple formats per scale in some ways. But we never actually found any demand or use for it in Bokeh, and that functionalit was never really implemented beyond the property types. So AFAIK that comment in the docs is just some ancient, decade-old cruft that ought to be removed. An issue or pull request to do so would be appropriate. [1]

Edit: I have gone ahead and made an issue for the API change fix at 3.0 but if you want to contribute something for the docs change now/sooner that is certainly appreciated.


  1. We really probably ought to also change the property types to just accept single strings for formats, instead of lists of strings, but that is a more involved undertaking. ↩︎

⌁   Link to post

End of archived discussion · Replies are disabled