I'm trying to use Bokeh to plot a Pandas
dataframe with a DateTime
column containing years and a numeric one. If the DateTime
is specified as x
, the behaviour is the expected (years in the x-axis). However, if I use set_index
to turn the DateTime
column into the index of the dataframe and then only specify the y
in the TimeSeries
I get time in milliseconds in the x-axis. A 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 behaviour or a bug? I would expect the same picture with both approaches.
Cheers!!
Bokeh used to add an index for internal reasons but as of not-so-recent versions (>= 0.12.x) it no longer does this. Also it's worth noting that the
bokeh.charts
API has been deprecated and removed. The equivalent code using the stablebokeh.plotting
API yields the expected result: