☰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

Formatting dateime axes

Community Support
Dave_Hirschfeld
Dave_Hirschfeld

I can see that there is a DatetimeTickFormatter in bokeh.objects but I can’t find any documentation on how to use it to format a datetime axis.

I tried to do the same as shown in:


plt.figure(

title="TimeSeries Plot"

title_text_font_size="20pt",

plot_width=800,

plot_height=600,

)

plt.hold()

plt.line(

series.index, series.values,

color='blue',

alpha=0.2,

tools="pan,box_zoom,wheel_zoom,reset,hover",

)

xformatter = DatetimeTickFormatter(formats=dict(months=["%b-%Y"]))

xaxis = DatetimeAxis(formatter=xformatter)

plt.curplot().add_layout(xaxis, 'below')

And this does indeed add an axis with the dates specified accordingly however I now have two axis, one with numbers and one with dates! Instead of adding an axis I want to simply specify a formatter for an existing axis.

Is there any way to do this?

Thanks,

Dave

⌁   Link to post
Bryan
Bryan

You can pull the formatter off an existing axis:

In [1]: from bokeh.plotting import *

In [2]: output_file("/tmp/foo.html")
Session output file '/tmp/foo.html' already exists, will be overwritten.

In [3]: line([1,2,3], [4,5,6])
Out[3]: <bokeh.objects.Plot at 0x110fe3d50>

In [4]: xaxis()[0].formatter
Out[4]: <bokeh.objects.BasicTickFormatter at 0x110fe3e90>

This is a BasicTickFormatter, but the principle is the same. So you could replace the formatter with an entirely new one, or set the months attribute of an existing formatter, etc.

Bryan

···

On Sep 24, 2014, at 10:47 AM, novin01@gmail.com wrote:

I can see that there is a DatetimeTickFormatter in `bokeh.objects` but I can't find any documentation on how to use it to format a datetime axis.

I tried to do the same as shown in:

https://github.com/ContinuumIO/bokeh/blob/d195f194b90416881ce2386049028eb4d35c9f47/examples/glyphs/daylight.py#L80-L82

plt.figure(
    title="TimeSeries Plot"
    title_text_font_size="20pt",
    plot_width=800,
    plot_height=600,
)
plt.hold()
plt.line(
    series.index, series.values,
    color='blue',
    alpha=0.2,
    tools="pan,box_zoom,wheel_zoom,reset,hover",
)
xformatter = DatetimeTickFormatter(formats=dict(months=["%b-%Y"]))
xaxis = DatetimeAxis(formatter=xformatter)
plt.curplot().add_layout(xaxis, 'below')

And this does indeed add an axis with the dates specified accordingly however I now have two axis, one with numbers and one with dates! Instead of adding an axis I want to simply specify a formatter for an existing axis.

Is there any way to do this?

Thanks,
Dave

--
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/b4bd75eb-bc41-4028-a919-e255843ef57f%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

⌁   Link to post
Dave_Hirschfeld
Dave_Hirschfeld

Thanks for the quick reply! That’s very useful to know, so much so that I’d suggest that it’s a worthy addition to the TimeSeries demo.

Thanks,

Dave

···

On Wednesday, 24 September 2014 15:51:37 UTC+1, Bryan Van de ven wrote:

You can pull the formatter off an existing axis:

In [1]: from bokeh.plotting import *

In [2]: output_file(“/tmp/foo.html”)

Session output file ‘/tmp/foo.html’ already exists, will be overwritten.

In [3]: line([1,2,3], [4,5,6])

Out[3]: <bokeh.objects.Plot at 0x110fe3d50>

In [4]: xaxis()[0].formatter

Out[4]: <bokeh.objects.BasicTickFormatter at 0x110fe3e90>

This is a BasicTickFormatter, but the principle is the same. So you could replace the formatter with an entirely new one, or set the months attribute of an existing formatter, etc.

Bryan

On Sep 24, 2014, at 10:47 AM, nov...@gmail.com wrote:

I can see that there is a DatetimeTickFormatter in bokeh.objects but I can’t find any documentation on how to use it to format a datetime axis.

I tried to do the same as shown in:

https://github.com/ContinuumIO/bokeh/blob/d195f194b90416881ce2386049028eb4d35c9f47/examples/glyphs/daylight.py#L80-L82

plt.figure(

title="TimeSeries Plot"
title_text_font_size="20pt",
plot_width=800,
plot_height=600,

)

plt.hold()

plt.line(

series.index, series.values,
color='blue',
alpha=0.2,
tools="pan,box_zoom,wheel_zoom,reset,hover",

)

xformatter = DatetimeTickFormatter(formats=dict(months=[“%b-%Y”]))

xaxis = DatetimeAxis(formatter=xformatter)

plt.curplot().add_layout(xaxis, ‘below’)

And this does indeed add an axis with the dates specified accordingly however I now have two axis, one with numbers and one with dates! Instead of adding an axis I want to simply specify a formatter for an existing axis.

Is there any way to do this?

Thanks,

Dave

⌁   Link to post
Bryan
Bryan

Thanks for the quick reply! That's very useful to know, so much so that I'd suggest that it's a worthy addition to the TimeSeries demo.

Dave, it's my pleasure. If you have a working example that you could submit as a Pull Request on GitHub it would be very welcome!

Bryan

⌁   Link to post

End of archived discussion · Replies are disabled