polakowo/vectorbt

Issues with combining multiple plots into subplots in 1 figure

ETTAN93 opened this issue · 1 comments

I am trying to combine for example a candlestick plot of the OHLC data, a MACD plot and a RSI plot. however, when adding the RSI plot as one of the subplots, the levels of the RSI plot is always added to the first subplot, i.e. the OHLC plot instead of the corresponding RSI plot. Why is that the case? How do I add it to the right subplot?

from plotly.subplots import make_subplots
import plotly.graph_objs as go

fig = make_subplots(
    rows=3, 
    cols=1, 
    shared_xaxes=True,
    vertical_spacing=0.01,
    row_width=[0.2, 0.4, 0.4] #starts from bottom 
)

# Candlestick plot
fig.add_trace(go.Candlestick(
    x=df.index,
    open=df['open'],
    high=df['high'],
    low=df['low'],
    close=df['close'],
    name='Candlestick'
), row=1, col=1)

# MACD plot
macd.plot(add_trace_kwargs={'row': 2, 'col': 1}, fig=fig)

# RSI plot
rsi.plot( 
    levels = (30,70),
    rsi_trace_kwargs={'line': {'color': 'blue'}},
    add_trace_kwargs={'row': 3, 'col': 1},  
    fig=fig  
)

# Update layout if needed
fig.update_layout(
    height=800, 
    width=1000, 
    xaxis_rangeslider_visible=False
)
fig.show()

image

You should provide yref to rsi.plot, such as yref="y3"