plotly.py
plotly.py copied to clipboard
[Bug] Bar yaxis range does not work with datetime
Hello, I would like to use range with go.Bar and datetime. From the docs https://plotly.com/python/reference/layout/yaxis/#layout-yaxis-range I should provide range with start and end in str.
range=[str(datetime.time(hour=0)), str(datetime.time(hour=10))],
But what I get is this:

The code:
import plotly.graph_objects as go
import datetime
figure = go.Figure()
figure.add_trace(
go.Bar(
x=x,
y=y,
legendgroup="duration",
legendgrouptitle_text="Sleep",
name="Sleep",
)
)
figure.update_layout(
xaxis=dict(
title="Date",
type="category",
),
yaxis=dict(
title="Time (hours)",
type="date",
tickformat="%H:%M",
range=[0, str(datetime.time(hour=10))],
),
)
The data:
>>> print(x)
['Nov 30 2021']
>>> print(y)
0 2021-12-06
Name: duration, dtype: datetime64[ns]
y is a pandas DataFrame