Hi,
I would like to plot multiple graphs, one of the graph involves multiple y-axes. In the subplot point of view, what is the y-axis sequence? I tried many combination but the y-axis2 - y-axis4 are still missing.
Below is the sample code for reference:
import plotly.graph_objects as go
fig = go.Figure()
fig = make_subplots(
rows=1, cols=4,
specs=[[{ârowspanâ: 1, âcolspanâ: 2}, None, {ârowspanâ: 1, âcolspanâ: 2}, None]],
horizontal_spacing =0.1, vertical_spacing =0.09)
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[2, 52, 62]), row=1, col=1)
fig.add_trace(go.Bar(x=[[âAâ, âAâ, âAâ], [1, 2, 3]], y=[4, 5, 60000], name=âyaxis1 dataâ, yaxis=ây2â), row=1, col=3)
fig.add_trace(go.Bar(x=[[âBâ, âBâ, âBâ], [2, 3, 4]], y=[40, 50, 60], name=âyaxis2 dataâ, yaxis=ây5â), row=1, col=3)
fig.add_trace(go.Bar(x=[[âCâ, âCâ, âCâ], [4, 5, 6]], y=[40000, 50000, 60000], name=âyaxis3 dataâ, yaxis=ây6â), row=1, col=3)
fig.add_trace(go.Bar(x=[[âDâ, âDâ, âDâ], [5, 6, 7]], y=[400000, 500000, 600000], name=âyaxis4 dataâ, yaxis=ây7â), row=1, col=3)
# Create axis objects
fig.update_layout(xaxis2=dict(domain=[0.6, 0.9]),
yaxis2=dict(title=âyaxis1 titleâ, titlefont=dict(color="#1f77b4"), tickfont=dict(color="#1f77b4")),
yaxis5=dict(title=âyaxis2 titleâ,titlefont=dict(color="#ff7f0e"),tickfont=dict(color="#ff7f0e"), anchor=âfreeâ, overlaying=ây2â, side=âleftâ, position=0.5),
yaxis6=dict(title=âyaxis3 titleâ,titlefont=dict(color="#d62728"),tickfont=dict(color="#d62728"), anchor=âx2â,overlaying=ây2â, side=ârightâ),
yaxis7=dict(title=âyaxis4 titleâ,titlefont=dict(color="#9467bd"),tickfont=dict(color="#9467bd"), anchor=âfreeâ,overlaying=ây2â, side=ârightâ,position=1))
fig.update_layout(width=1600, height=500)
fig.update_xaxes(rangeslider_visible=False)
fig.show()
Thanks for your advice.
BR,
Jason Tam






