1
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?

Abhay kumar
  • 203
  • 1
  • 4
  • 13
  • Since version 4.0 plotly is offline only so you can avoid `import plotly.offline ` – rpanai May 29 '20 at 17:18
  • It's not that clear what do you want to achieve. Do you mind to elaborate/provide examples? – rpanai May 29 '20 at 17:38
  • 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 May 30 '20 at 18:31
  • 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 May 31 '20 at 11:34
  • you need to [link your xaxis](https://plotly.com/python/subplots/#subplots-with-shared-xaxes) when you use `make_subplots`, and then use `fig.update_xaxes(matches='x')` at the end, see [here](https://stackoverflow.com/a/61799255/11305111). – jayveesea Jun 01 '20 at 14:35
  • Does this answer your question? [Plotly with shared yaxes but "linked" xaxes](https://stackoverflow.com/questions/61794034/plotly-with-shared-yaxes-but-linked-xaxes) – jayveesea Jun 01 '20 at 14:36
  • 1
    Yep...it helps..thank you – Abhay kumar Jun 01 '20 at 16:23

2 Answers2

2

Add line below.

fig.update_xaxes(matches='x')
Jeereddy
  • 1,050
  • 8
  • 16
1

first select the subplot you don't want the slider to apper, lets think it is the row=1 and col=1 subplot

then add the line

fig.update_xaxes(row=1, col=1, rangeslider_visible=False)

then both of the charts will have only one slider