bokeh figure change x-axis to dates

I am playing with this example https://bokeh.pydata.org/en/latest/docs/gallery/brewer.html

r = [[1, 4, 5], [0,0,0], [0,0,0], [1,2,3]]
import pandas as pd
df = pd.DataFrame(data=r).add_prefix('y')

from bokeh.plotting import figure
p = figure(x_range=(0, 3), y_range=(0, 20))

And it plots data with x-axis values 0,1,2,3 How can I change x-axis values to dates in datetime or standard format? e.g. dates = [‘2018-06-01’, ‘2018-06-02’, ‘2018-06-03’, ‘2018-06-04’]

I see option to figure as x_axis_type="datetime" but not sure how to set x_range to dates. Also graph doesn’t plot properly if I willy nilly change x_range=(0, 3) e.g. to x_range=(3,6)

I passed date as x_range=(datetime.date(2018, 6, 1), datetime.date(2018, 6, 3) and it plots dates on x-axis as '6/01, 8h, 16h, 6/02…But graph is not plotting I think for some reason it's expecting x-range as0,1,2,3`?

···

On Monday, June 4, 2018 at 11:03:54 AM UTC-5, Sandesh Kakade wrote:

I am playing with this example https://bokeh.pydata.org/en/latest/docs/gallery/brewer.html

r = [[1, 4, 5], [0,0,0], [0,0,0], [1,2,3]]
import pandas as pd
df = pd.DataFrame(data=r).add_prefix('y')

from bokeh.plotting import figure
p = figure(x_range=(0, 3), y_range=(0, 20))

And it plots data with x-axis values 0,1,2,3 How can I change x-axis values to dates in datetime or standard format? e.g. dates = [‘2018-06-01’, ‘2018-06-02’, ‘2018-06-03’, ‘2018-06-04’]

I see option to figure as x_axis_type="datetime" but not sure how to set x_range to dates. Also graph doesn’t plot properly if I willy nilly change x_range=(0, 3) e.g. to x_range=(3,6)

Hi,

Your question is not very clear, and you have not included complete code. Offhand, it looks like you are not passing x values that are actual date times. On a date time axis, x=2 means "2 milliseconds after midnight January 1, 1970). You need to use real date time values for your x coordinates, e.g

  https://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#datetime-axes

Thanks,

Bryan

···

On Jun 4, 2018, at 09:48, [email protected] wrote:

I passed date as x_range=(datetime.date(2018, 6, 1), datetime.date(2018, 6, 3) and it plots dates on x-axis as '6/01, 8h, 16h, 6/02....` But graph is not plotting I think for some reason it's expecting x-range as 0,1,2,3?

On Monday, June 4, 2018 at 11:03:54 AM UTC-5, Sandesh Kakade wrote:
I am playing with this example https://bokeh.pydata.org/en/latest/docs/gallery/brewer.html

r = [[1, 4, 5], [0,0,0], [0,0,0], [1,2,3]]
import pandas as
pd
df
= pd.DataFrame(data=r).add_prefix('y')

from bokeh.plotting import
figure
p
= figure(x_range=(0, 3), y_range=(0, 20))
And it plots data with x-axis values 0,1,2,3 How can I change x-axis values to dates in datetime or standard format? e.g. dates = ['2018-06-01', '2018-06-02', '2018-06-03', '2018-06-04']

I see option to figure as x_axis_type="datetime" but not sure how to set x_range to dates. Also graph doesn't plot properly if I willy nilly change x_range=(0, 3) e.g. to x_range=(3,6)

--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/9c5793ad-4e08-4188-87bc-2a61849bfde4%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.