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