Search code examples
pythonpython-3.xplotlyplotly-dashdashboard

How do I avoid repeating the range selector buttons in plotly?


I have a subplot that uses a range selector.

fig = make_subplots(rows = 2, cols = 1)

fig.add_trace(
    go.Scatter(x=list(df.Date), y=list(df.Measure)), row = 1, col = 1)

fig.add_trace(
    go.Scatter(x=list(dfsecond.Date), y=list(dfsecond.Measure)), row = 2, col = 2)

fig.update_layout(
    xaxis=dict(
        rangeselector=dict(
            buttons=list([
                dict(count=1,
                     label="1m",
                     step="month",
                     stepmode="backward")
            ])
        ),
        rangeslider=dict(
            visible=True
        ),
        type="date"
    )
)

The range selector buttons show up twice. They show up once in the first row and again in the second row. I want the range selector to show up just one time in the first row.


Solution

  • So this is what I did for my project and it has time period buttons for stock charts and I edited your code to look just like mine and this worked for me with 3 rows of charts below my main chart, which is where the buttons are. Here is the code:

    fig.update_layout(
        xaxis = dict(
            rangeselector_visible = True,
            rangeselector = dict(
                buttons = list([
                    dict(
                        count = 1,
                        label = "1m",
                        step = "month",
                        stepmode = "backward"
                    )
                ]),
            )
        )
    )