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

fail to update_xaxes rangebreaks by datetime

Open xkungfu opened this issue 4 years ago • 1 comments

data df: ` id date_time time_hms time_second price time_date

0 2021-05-31 09:25:00 09:25:00 33900 7 2021-05-31

1 2021-05-31 09:30:00 09:30:00 34200 8 2021-05-31

2 2021-05-31 09:30:01 09:30:01 34201 7 2021-05-31

3 2021-05-31 09:30:02 09:30:02 34202 6 2021-05-31

4 2021-05-31 09:30:03 09:30:03 34203 5 2021-05-31

... ... ... ... ...

24264 2021-06-04 14:56:56 14:56:56 53816 7 2021-06-04

24265 2021-06-04 14:56:57 14:56:57 53817 6 2021-06-04

24266 2021-06-04 14:56:58 14:56:58 53818 4 2021-06-04

24267 2021-06-04 14:56:59 14:56:59 53819 7 2021-06-04

24268 2021-06-04 15:00:00 15:00:00 54000 8 2021-06-04 `

code: ` import pandas as pd import plotly.express as px import plotly.io as pio

    fig = px.line(df,
                  x = "date_time",
                  y = "price"
                )

    fig.update_xaxes(
        rangebreaks=[
            dict(bounds=["2021-06-01 09:25:00", "2021-06-04 09:25:01"])  # hide by datetime
        ]
    )

    pio.write_html(fig, file="stock_graph_px.html", auto_open=True)

`

the result html page is blank.

as document, rangebreaks only work for "date" .

but, how to deal with datetime breaks?

is there a simple way to set axis datetime breaks?

plotly==4.14.3 Python 3.8.5

xkungfu avatar Jun 06 '21 09:06 xkungfu

It works with hours:

dict(bounds=[15, 9], pattern="hour")

paulhybryant avatar Jun 14 '22 09:06 paulhybryant