I plot some data in subplots. Each subplot is autoscaled by default.
For easy comparison, I sometimes want to have the same scale in all subplots.
Is it possible to do this with a button, in the style of https://plotly.com/python/custom-buttons/
Sample code with buttons:
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import pandas as pd
# Load dataset
df = pd.read_csv(
"https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv")
df.columns = [col.replace("AAPL.", "") for col in df.columns]
# Initialize figure
fig = make_subplots(rows=1, cols=2)
# Add Traces
fig.add_trace(
go.Scatter(x=list(df.index),
y=list(df.High*2),
name="High",
line=dict(color="#33CFA5")),
row = 1, col = 1
)
fig.add_trace(
go.Scatter(x=list(df.index),
y=list(df.Low),
name="Low",
line=dict(color="#F06A6A")),
row = 1, col = 2
)
# Add Buttons
fig.update_layout(
updatemenus=[
dict(
type="buttons",
direction="right",
active=0,
x=0.57,
y=1.2,
buttons=list([
dict(label="Autoscale for each",
method="update",
args=[ # set autoscale for each subplot
{"title": "Autoscale"}]),
dict(label="Same scale",
method="update",
args=[ # set same scale for all. how?
{"title": "Same scale for all"}]),
]),
)
])
# Set title
fig.update_layout(
title_text="Yahoo",
)
fig.show()
P.S. I know how to do this manually:
fig.update_yaxes(range=[ymin, ymax])