plotly / plotly/plotly.py

Bar yaxis range does not work with datetime

Open
#3,501 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied Python reproduction using go.Bar and figure.update_layout, then compare the yaxis type, tickformat, and range values with the referenced yaxis range documentation. Done means a datetime y-axis accepts the requested bounds and displays the bar within the intended 00:00–10:00 range.

Written by the indexing model from the issue text.

Assessment

Tech stack
pandas, python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.