Hi,
I’m plotting a
I’m trying to get the shared_yaxis feature for a Figure consisting of 4 subplot with secondary axis working.
Unfortunately the shared zoom (in y direction) is only working on the trace that is plotted on the primary axis.
Here is an example:
from plotly.subplots import make_subplots
import plotly.graph_objects as go
fig = make_subplots(
rows=2,
cols=2,
specs=[
[{"secondary_y": True}, {"secondary_y": True}],
[{"secondary_y": True}, {"secondary_y": True}]
],
shared_xaxes="all",
shared_yaxes = "all",
vertical_spacing=0.06,
horizontal_spacing=0.04
)
# data
X = ["yesterday", "today", "tomorrow"]
Y_primary = [2,3,4]
Y_secondary = [-2,-4,-16]
#top left
fig.add_trace(go.Bar(x=X, y=Y_primary, name="prinmary", marker_color="lightsteelblue", showlegend=False),row=1, col=1, secondary_y=False)
fig.add_trace(go.Scatter(x=X, y=Y_secondary, name="secondary", showlegend=False,line=dict(color="royalblue", width=2)),row=1, col=1, secondary_y=True)
#top right
fig.add_trace(go.Bar(x=X, y=Y_primary, name="prinmary", marker_color="lightsteelblue", showlegend=False),row=1, col=2, secondary_y=False)
fig.add_trace(go.Scatter(x=X, y=Y_secondary, name="secondary", showlegend=False,line=dict(color="royalblue", width=2)),row=1, col=2, secondary_y=True)
#bottom left
fig.add_trace(go.Bar(x=X, y=Y_primary, name="prinmary", marker_color="lightsteelblue", showlegend=False),row=2, col=1, secondary_y=False)
fig.add_trace(go.Scatter(x=X, y=Y_secondary, name="secondary", showlegend=False,line=dict(color="royalblue", width=2)),row=2, col=1, secondary_y=True)
#bottom right
fig.add_trace(go.Bar(x=X, y=Y_primary, name="prinmary", marker_color="lightsteelblue", showlegend=False),row=2, col=2, secondary_y=False)
fig.add_trace(go.Scatter(x=X, y=Y_secondary, name="secondary", showlegend=False,line=dict(color="royalblue", width=2)),row=2, col=2, secondary_y=True)
fig.update_layout(
yaxis2 = dict(visible=False),
yaxis6 = dict(visible=False)
)
fig.show()
Thanks for your help!
Christian