plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

[Bug] Bar yaxis range does not work with datetime

Open hidr0 opened this issue 4 years ago • 0 comments

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:

Screenshot 2021-12-06 at 11 38 26

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

hidr0 avatar Dec 06 '21 09:12 hidr0