The rangeslider
is associated to the x-axis. Hence to bind the slider to all subplots you must define shared xaxes:
import plotly.graph_objects as go
import pandas as pd
from plotly.subplots import make_subplots
# Load data
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]
fig = make_subplots(rows=2, cols=1, vertical_spacing=0.065, shared_xaxes=True)
fig.add_trace(
go.Scatter(x=list(df.Date), y=list(df.High)), 1, 1)
fig.add_trace(
go.Scatter(x=list(df.Date), y=list(df.High)), 2, 1);
fig.update_layout(
title_text="Time series with range slider and selectors")
fig.update_layout(
xaxis=dict(
rangeselector=dict(
buttons=[
dict(count=1,
label="1m",
step="month",
stepmode="backward"),
dict(count=6,
label="6m",
step="month",
stepmode="backward"),
dict(count=1,
label="YTD",
step="year",
stepmode="todate"),
dict(count=1,
label="1y",
step="year",
stepmode="backward"),
dict(step="all")
]),
type="date"),#end xaxis definition
xaxis2_rangeslider_visible=True,
xaxis2_type="date"
);
fig.show()