I am new to plotly and I am trying to make a flexible setup using plotly (and streamlit) with NxM subplots with each plot having one x-axis and multiple y-axes. The x-axes and y-axes are shared between plots.
Below a minimal example with only one subplot, with three y-axes. The resulting plot only has one y-axis (See plot). Can anyone help me with this?
from plotly.subplots import make_subplots
import plotly.graph_objects as go
# Create a figure with one subplot and secondary y-axis
fig = make_subplots(rows=1, cols=1)
# Add a trace to the primary y-axis
fig.add_trace(
go.Scatter(x=[1, 2, 3], y=[10, 20, 30], name="Primary Y", yaxis="y"),
row=1, col=1
)
# Add a trace to the secondary y-axis (y2)
fig.add_trace(
go.Scatter(x=[1, 2, 3], y=[0.1, 0.4, 0.9], name="Secondary Y", yaxis="y2"),
row=1, col=1
)
# Add a trace to the tertiary y-axis (y3)
fig.add_trace(
go.Scatter(x=[1, 2, 3], y=[100, 200, 300], name="Tertiary Y", yaxis="y3"),
row=1, col=1
)
print(fig.layout)
# Update layout for the primary and secondary axes
fig.update_layout(
title="Minimal Example with Three Y-Axes",
xaxis=dict(title="Producing Months"),
yaxis=dict(title="Primary Y-Axis", side="left", range=[0,1000]),
yaxis2=dict(title="Secondary Y-Axis", side="left", anchor="x", overlaying="y", range=[0,1], autoshift=True),
yaxis3=dict(title="Tertiary Y-Axis", side="left", anchor="x", overlaying="y", range=[0,500], autoshift=True),
)
# Show the figure
fig.show()