Skip to content Skip to sidebar Skip to footer

Bokeh Glyph Coordinates With X_axis_type 'datetime'

I am attempting to add a simple text string (glyph) to a Bokeh plot which uses x_axis_type='datetime' My code (stripped to its essentials ) is as follows: p = figure(plot_width=90

Solution 1:

When the x_axis_type attr is set to 'datetime', Bokeh will plot things along the x-axis according to seconds-since-epoch. The easiest solution is to use datetime.datetime (not .date) and then cast your dt object to seconds-since-epoch using the timestamp() method (which will give the ~1.50e9 number you're getting) then use that for your x-coordinate.

$ from datetime import datetime$ dt = datetime.now()$ dt> datetime.datetime(2015, 6, 17, 10, 41, 34, 617709)$ dt.timestamp()> 1434555694.617709

Solution 2:

See the following SO question/answer for the python2 answer to my problem:

How can I convert a datetime object to milliseconds since epoch (unix time) in Python?

Thank you @Luke Canavan for pointing me in the right direction(!)

Post a Comment for "Bokeh Glyph Coordinates With X_axis_type 'datetime'"