How to update the rangebreaks of a date x axis so that it shows 9:30 am to 4:pm only?

I am visualizing intra-day market data with one bar per minute. I use the following code to make timeline skip weekends and show 9: AM to 4: PM data:

import pandas as pd
import numpy as np
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from datetime import datetime

fig = go.Figure()

df = pd.date_range(start='2016-01-01', end='2016-01-5', freq='60s').to_frame(index=False, name='candle_date')

df['price1'] = np.random.randint(0, 3, size=(len(df)))

fig.add_trace(go.Scatter(name='Price 0', x=df.candle_date, y=df.price1))

# Add range slider
    xaxis_rangeslider_thickness = 0.1,
# See this:
        dict(bounds=[16, 9], pattern="hour"), #hide hours outside of 9am-5pm
        dict(bounds=["sat", "mon"])
fig.update_layout(hovermode="x unified")


Stock market operation starts from 9:30 AM not 9:00 AM. How do I update above code to start from 9:30 AM ?

Thank you,

Hi @python-trader
Can you please add a MRE to your posts. That would make it a lot easier for us to test your code out and try to help you.

Thank you,

1 Like

Greetings @adamschroeder , I’ve added a reproduceable code and additional details.

Any help would be appreciated.

Hi @python-trader,

I believe bounds=[16, 9.5] should do it for you.

Let me know if this works!

1 Like

@jlfsjunior ,

Yes, it does work. I though I did tested that. Mistake from my part.

Thank you for help.