I have an OHLC Chart in row1, col1 of my plot. I have a single line indicator in row2 col1 of my chart. How do I control both subplots with the slider that the OHLC generates. In the example below the second graph is RSI. I can zoom into the OHLC but the subplot below stays static which defeats the purpose of it.
fig = make_subplots(rows=2, cols=1,specs=[[{"secondary_y": True}],
[{"secondary_y": True}]])
fig.add_trace(go.Candlestick(x=df['Date'],
open=df['Open SPY'],
high=df['High SPY'],
low=df['Low SPY'],
close=df['Close SPY'],
yaxis='y1',
name='OHLC',
increasing={'line': {'width': 1}},
decreasing={'line': {'width': 1}})
,row=1, col=1
)
fig.add_trace(go.Line(x=df['Date'],
y = df['Correlation'],
yaxis='y2',
name='SMA',
line=dict(color="indigo",width=1)
),row=2, col=1)
fig.update_xaxes(showspikes=True, showticklabels=False, spikemode='across',spikecolor="grey",spikethickness=1)
fig.update_yaxes(title_text="RSI", range=[-1, 1], row=2, col=1)
fig.update_layout(xaxis={'type': 'category'},height=1000,width=1200,hoverdistance=0)
Data set can be replicated below
import talib
import pandas_datareader as dr
df = dr.get_data_yahoo('SPY')
df['RSI'] = talib.RSI(df['Close'],14)