TimeSeries in Bokeh using an index data frame

I am trying to use Bokeh to build a Pandas frame with a DateTime column containing years and numeric. If the DateTime parameter is specified as x , the behavior is expected (years along the x axis). However, if I use set_index to turn the DateTime column into an index on the data frame, and then specify only y in the TimeSeries , I get the time in milliseconds along the x axis. Minimal example

 import pandas as pd import numpy as np from bokeh.charts import TimeSeries, output_file, show output_file('fig.html') test = pd.DataFrame({'datetime':pd.date_range('1/1/1880', periods=2000),'foo':np.arange(2000)}) fig = TimeSeries(test,x='datetime',y='foo') show(fig) output_file('fig2.html') test = test.set_index('datetime') fig2 = TimeSeries(test,y='foo') show(fig2) 

Is this the expected behavior or error? I would expect the same picture with both approaches.

Hooray!!

+7
python pandas time-series bokeh
source share
1 answer

Bokeh used to add an index for internal reasons, but compared to versions not so recently (> = 0.12.x), it no longer does this. It is also worth noting that the bokeh.charts API bokeh.charts deprecated and removed. Equivalent code using the stable bokeh.plotting API gives the expected result:

 import pandas as pd import numpy as np from bokeh.plotting import figure, output_file, show from bokeh.layouts import row output_file('fig.html') test = pd.DataFrame({'datetime':pd.date_range('1/1/1880', periods=2000),'foo':np.arange(2000)}) fig = figure(x_axis_type="datetime") fig.line(x='datetime',y='foo', source=test) test = test.set_index('datetime') fig2 = figure(x_axis_type="datetime") fig2.line(x='datetime', y='foo', source=test) show(row(fig, fig2)) 

enter image description here

0
source share

All Articles