Pre-defined range buttons

In fact a simpler syntax is to pass directly xaxis.range in the args as in

import plotly.graph_objects as go

import pandas as pd

# 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]

# Create figure
fig = go.Figure()

fig.add_trace(
    go.Scatter(x=list(df.Date), y=list(df.High)))

# Set title
fig.update_layout(
    title_text="Time series with range slider and selectors"
)

# Add range slider
fig.update_layout(
    xaxis=dict(
       
        rangeslider=dict(
            visible=True
        ),
        type="date",
        range=('2015-04-01', '2017-01-01')
    )
)
fig.update_layout(
    updatemenus=[
        dict(
            type="buttons",
            buttons=[
                dict(label="Custom",
                     method="relayout",
                     args=["xaxis.range", ('2015-07-01', '2015-09-01'),]),]
        )]
)
fig.show()
1 Like