-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
hello
I want to make 5 subplot in one column, each subplot contains one trace. each trace share exactly same date time index.
I have tried multiple option to align xaxis across 5 subplot, that includes shared_xaxes= True, shared_xaxes='columns', assign reference axis, use fix range. all options did not work well, always display randomly mis-aligned at the plot end. there is no fixed pattern for this mis-alignment, sometimes the mis-alignment appears at first and 2nd plot, while some appears at 3rd and 4th plot. still some cases align well.
I think it may associate with my axes type assignment, to wavier weekend gap in candlestick plot. all x-axis were assigned as category.
can any contributor suggest an solution to fix this mis-align issue?
thank in advance.
below is the code and plot.
fig = make_subplots(rows=5, cols=1, shared_xaxes='columns', vertical_spacing=0.03, specs=[[{"type": "Candlestick", "secondary_y": False}],[{"type": "xy", "secondary_y": True}],[{"type": "Candlestick", "secondary_y": False}],[{"type": "xy", "secondary_y": True}],[{"type": "xy", "secondary_y": True}]])
fig.add_trace(go.Candlestick(x=df.index, open=open, high=high, low=low, close=close, name=stock_symbol.upper()+'_'+Period+'_'+Interval),row=1, col=1, secondary_y=False)
fig.add_trace(go.Scatter(x=df.index, y=macd, name='macd'+'_'+Period+'_'+Interval), row=2, col=1, secondary_y=False)
fig.add_trace(go.Scatter(x=df.index, y=macdsignal, name='macd_signal'+'_'+Period+'_'+Interval), row=2, col=1, secondary_y=False)
marker_color_list=pd.Series(index=df.index, dtype=str, name='marker_color')
fig.add_trace(go.Candlestick(x=df.index, open=open, high=high, low=low, close=close, name=stock_symbol.upper()+''+Period+''+Interval),row=3, col=1, secondary_y=False)
fig.update_yaxes(title_text=stock_symbol.upper() + "_" + Period, range=[min(close)*0.99, max(close)*1.01], row=3, col=1)
fig.add_trace(go.Scatter(x=df.index, y=macd, name='macd'+'_'+Period+'_'+Interval), row=4, col=1, secondary_y=False)
fig.add_trace(go.Scatter(x=df.index, y=macdsignal, name='macd_signal'+'_'+Period+'_'+Interval), row=4, col=1, secondary_y=False)
fig.add_trace(go.Bar(x=df.index, y=macdhist, name='macdhist'+'_'+Period+'_'+Interval, marker_color =marker_color_list), row=4, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x=df.index, y=rsi, name='RSI'+'_'+Period+'_'+Interval),row=5, col=1)
xaxis_dict= dict(type='category',visible= False)
xaxis5_dict=(dict(categoryorder='array',
showticklabels=True,
tickangle=45,
tickfont=dict(family='Arial, sans-serif',
size=12,
color='#909090'),
rangebreaks= [dict(bounds=["sat", "mon"]),
dict(pattern='hour', bounds=[20, 4]),#hide weekends
# # # dict(values=us_holidays)
]
),
dict(categoryorder='array',
showticklabels=True,
tickangle=45,
tickfont=dict(family='Arial, sans-serif',
size=12,
color='#909090')
)
)[Interval in long_interval_list]
fig.update_layout( height=800,
hovermode="x",
xaxis1=xaxis_dict,
xaxis2=xaxis_dict,
xaxis3=xaxis_dict,
xaxis4=xaxis_dict,
xaxis5=xaxis5_dict,
xaxis_rangeslider=dict(visible=False),
xaxis3_rangeslider=dict(visible=False)
)
fig.update_layout(xaxis1=dict(matches= 'x5'),
xaxis2=dict(matches= 'x5'),
xaxis3=dict(matches= 'x5'),
xaxis4=dict(matches= 'x5'),
xaxis5=dict(matches= 'x5'),
)
