Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set the x-axis as datetimes on a bokeh plot?

I'm using bokeh with an ipython notebook.

I want to plot a line graph in bokeh using a pandas DataFrame containing datetimes:

import pandas as pd from datetime import datetime as dt from bokeh.io import output_notebook from bokeh.charts import Bar, Line, show  df = pd.DataFrame(data=[1,2,3],                   index=[dt(2015, 1, 1), dt(2015, 1, 2), dt(2015, 1, 3)],                   columns=['foo'])  output_notebook() show(Line(df)) 

However, bokeh uses microseconds! Why is this? How do I fix it?

bokeh plot of line

like image 649
Wilfred Hughes Avatar asked Nov 23 '15 10:11

Wilfred Hughes


People also ask

What is bokeh plotting?

The bokeh. plotting API is Bokeh's primary interface, and lets you focus on relating glyphs to data. It automatically assembles plots with default elements such as axes, grids, and tools for you.


1 Answers

As of bokeh 0.12.3, you can now do:

p = figure(..., x_axis_type='datetime', ...) 
like image 135
Emmanuel Avatar answered Sep 22 '22 07:09

Emmanuel