Hi @raf.martone,
Here is the code that updates simultaneously all subplots:
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import numpy as np
fig = make_subplots(rows=1, cols=2)
x = list(range(1,6))
y2 = [4]*5
y1 = [6]*5
fig.add_trace(go.Scatter(x=x, y=y1), 1, 1)
fig.add_trace(go.Scatter(x=x, y=y2), 1, 2)
fig.update_layout(width=700, height=500,
yaxis_range=[0,10],
yaxis2_range=[0,10]);
fig.update_layout(
updatemenus=[
dict(
buttons=[
dict(
args=[{'y':[y1, y2]},
{'traces': [0,1]}],
label="A",
method="restyle"
),
dict(
args=[{'y':[y2, y1]},
{'traces': [0, 1]}], #restyle both fig.data[0], fig.data[1]
label="B",
method="restyle"
),
],
showactive=True,
x=-0.2,
xanchor="left",
y=1,
yanchor="top"
)
]
)
label="A",
method="restyle"
),
dict(
args=[{'y':[y2, y1]},
{'traces': [0, 1]}], #restyle both fig.data[0], fig.data[1]
label="B",
method="restyle"
),
],
showactive=True,
x=-0.2,
xanchor="left",
y=1,
yanchor="top"
)
]
)
Note that because both subplots display the same trace type (Scatter), we give a list of lists [y1, y2], respectively, [y2,y1], to update y. The dict {'traces' :[0,1]}
informs plotly.js that the first list is for updating y in the first trace added to the figure, while the second list, for the second trace.
PS When you provide code with your question, please donβt upload an image, but use the Markdown rule to display code https://www.markdownguide.org/basic-syntax/#code:
your code