Range Breaks not working properly

I get a weird plot. So when I use 1 minute data as follows

symbols = [‘NVDA’, ‘AMD’]
data = yf.download(symbols, period=‘5d’, interval=‘1m’)

data=data[‘Adj Close’]

data=(data-data.iloc[0])/data.iloc[0]

data.index=data.index.tz_convert(‘US/Eastern’)

import plotly.express as px
fig = px.line(data.melt(value_name=‘Close’, ignore_index=False), color=‘Ticker’)
fig.update_xaxes(rangebreaks=[dict(bounds=[“sat”, “mon”]),
dict(bounds=[16, 9.5], pattern=“hour”)] # hide hours from 4pm to 9:30am
) # Hide weekends
fig.show()

I get

but when I change it to using interval = ‘5m’ instead of ‘1m’ i.e.

data = yf.download(symbols, period=‘5d’, interval=‘5m’)

for some reason it plots nicely? Any thoughts?

1 Like

Looking at the graph data created, I see scattergl() for 1 minute but scatter() for 5 minutes. scattergl() does not have a rangebreak function, I believe, so the graph is not created. I have not checked the source code, but it may be that the graph type changes depending on the number of data. As a workaround, the graph can be obtained by changing the graph type to the last one.

fig.plotly_restyle({'type': 'scatter'})
fig.show()

Nice catch! Thanks.