1
votes
import pandas as pd
import plotly.graph_objs as go
from plotly.subplots import make_subplots

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(1, 2)

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

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


fig.update_layout(
    xaxis=dict(
    rangeselector=dict(
        buttons=list([
            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")
        ])
    ),
    rangeslider=dict(
        visible=True
    ),
    type="date"
)
)


import plotly.offline as pyo
pyo.plot(fig)

I want to create one common slider for both of the plots. Currently there are two graphs but slider is working only for one of them. Is it possible to make the current slider common for all the multiple graphs in a subplot?

1
Since version 4.0 plotly is offline only so you can avoid import plotly.offline - rpanai
It's not that clear what do you want to achieve. Do you mind to elaborate/provide examples? - rpanai
Currently there are two graphs being generated by the above graph but the slider is working only for one of the graphs. I want a common slider for both of the graphs. - Abhay kumar
When I plot this in jupyter the slider works on both plots. Also, just fyi, the indentation is not correct on the for i in range(3): loop. It needs indentation all the way to steps.append(step). - jayveesea
Yep...it helps..thank you - Abhay kumar

1 Answers

2
votes

Add line below.

fig.update_xaxes(matches='x')