Datetime on y axis for hbar and/or harea

I am trying to make a hbar in which the vetrical axis (y_axis) is a datetime.

The following does not work:

from bokeh.sampledata.stocks import AAPL
AAPL[‘date’] = to_datetime(AAPL[‘date’])
ko = figure(y_axis_type=“datetime”)
ko.hbar(y=AAPL[‘date’], right=AAPL[‘open’], height=1006060*24, color=“lightgrey”)
ko.line(y=AAPL[‘date’], x=AAPL[‘open’], color=“grey”)

What puzzeles me is that it works if I remove the hbar line:

ok = figure(y_axis_type=“datetime”)
ko.line(AAPL[‘open’], AAPL[‘date’], color=“grey”)

Or when I change the x/y axis:

ok = figure(x_axis_type=“datetime”)
ok.vbar(AAPL[‘date’], top=AAPL[‘open’], width=1006060*24, color=“lightgrey”)

Is there a subtle way to count the datetime in nanoseconds in that case?

The first argument to hbar is y. The first argument to line is x. I’m not sure what you want to achieve, but you’re definitely mixing something up.

To help mitigate such issues, you can just avoid using positional arguments with Bokeh altogether. Well, maybe except for really trivial cases like ColumnDataSource(data).

Thanks. Nice spot.
I edited the answer according to your solution just in case someone else looks for a working example.

1 Like