Greetings,
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
fig.update_layout(
xaxis=dict(type="date"),
xaxis_rangeslider_visible=True,
xaxis_rangeslider_thickness = 0.1,
xaxis_type="date"
)
# See this: https://plotly.com/python/reference/layout/xaxis/#layout-xaxis-rangebreaks-items-rangebreak-pattern
fig.update_xaxes(
rangebreaks=[
dict(bounds=[16, 9], pattern="hour"), #hide hours outside of 9am-5pm
dict(bounds=["sat", "mon"])
]
)
fig.update_layout(hovermode="x unified")
fig.show()
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,