# Using one slider to control multiple subplots (NOT multiple traces)

**URL:** <https://community.plotly.com/t/using-one-slider-to-control-multiple-subplots-not-multiple-traces/13955>\
**Category:** 📊 Plotly Python\
**Created:** [September 25, 2018, 8:37pm UTC](https://community.plotly.com/t/using-one-slider-to-control-multiple-subplots-not-multiple-traces/13955 "2018-09-25T20:37:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![carpenter](https://avatars.discourse-cdn.com/v4/letter/c/bc8723/32.png) [@carpenter](https://community.plotly.com/u/carpenter)\
**Post date:** [September 25, 2018, 8:37pm UTC](https://community.plotly.com/t/using-one-slider-to-control-multiple-subplots-not-multiple-traces/13955/1 "2018-09-25T20:37:05Z")

</div>

I have been making slider charts such as the one here: [https://plot.ly/python/sliders/](https://plot.ly/python/sliders/). However, how can create a slider that controls multiple _subplots_? Note that I’m trying to control multiple traces (therefore, the link [here](https://stackoverflow.com/questions/47554585/plot-ly-using-slider-control-with-multiple-plots) doesn’t help). What I want is to add a slider to a set of subplots, such as the content of all the subplots move as I move the slider.

Is that doable in Plotly through the Python API?

---

<div class="post-metadata">

**Author:** ![jmmease](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jmmease/32/3706_2.png) [@jmmease](https://community.plotly.com/u/jmmease)\
**Post date:** [September 26, 2018, 9:57am UTC](https://community.plotly.com/t/using-one-slider-to-control-multiple-subplots-not-multiple-traces/13955/2 "2018-09-26T09:57:16Z")

</div>

Hi @carpenter,

This isn’t impossible, but it would require a bit of bookkeeping. Essentially you would need to keep track of the order in which you add the traces to the figure subplots, and then duplicate the `# Toggle i'th trace to "visible"` line once for the trace that you want to be visible in each subplot.

-Jon

---

<div class="post-metadata">

**Author:** ![carpenter](https://avatars.discourse-cdn.com/v4/letter/c/bc8723/32.png) [@carpenter](https://community.plotly.com/u/carpenter)\
**Post date:** [September 26, 2018, 6:51pm UTC](https://community.plotly.com/t/using-one-slider-to-control-multiple-subplots-not-multiple-traces/13955/3 "2018-09-26T18:51:45Z")

</div>

Thank you. Can you give me a quick example? I’m a bit confused as to how to proceed.

---

<div class="post-metadata">

**Author:** ![jmmease](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jmmease/32/3706_2.png) [@jmmease](https://community.plotly.com/u/jmmease)\
**Post date:** [September 28, 2018, 9:43am UTC](https://community.plotly.com/t/using-one-slider-to-control-multiple-subplots-not-multiple-traces/13955/4 "2018-09-28T09:43:41Z")

</div>

Hi @carpenter,

Here’s an example with two subplots, and 3 traces per subplot

```python
import plotly.graph_objs as go
from plotly.tools import make_subplots

fig = make_subplots(1, 2)

fig.add_scatter(y=[1, 3, 2], row=1, col=1, visible=True)
fig.add_scatter(y=[3, 1, 1.5], row=1, col=1, visible='legendonly')
fig.add_scatter(y=[2, 2, 1], row=1, col=1, visible='legendonly')
fig.add_scatter(y=[1, 3, 2], row=1, col=2, visible=True)
fig.add_scatter(y=[1.5, 2, 2.5], row=1, col=2, visible='legendonly')
fig.add_scatter(y=[2.5, 1.2, 2.9], row=1, col=2, visible='legendonly')

steps = []
for i in range(3):
    step = dict(
        method = 'restyle',  
        args = ['visible', ['legendonly'] * len(fig.data)],
    )
    step['args'][1][i] = True
    step['args'][1][i+3] = True
    steps.append(step)

sliders = [dict(
    steps = steps,
)]

fig.layout.sliders = sliders

go.FigureWidget(fig)

```

 ![sliderSubplots](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/3/380059008c3cb18a03021f2f146873fa4d9ae621.gif)

Hope that helps!  
-Jon

---

<div class="post-metadata">

**Author:** ![carpenter](https://avatars.discourse-cdn.com/v4/letter/c/bc8723/32.png) [@carpenter](https://community.plotly.com/u/carpenter)\
**Post date:** [October 12, 2018, 7:28pm UTC](https://community.plotly.com/t/using-one-slider-to-control-multiple-subplots-not-multiple-traces/13955/5 "2018-10-12T19:28:31Z")

</div>

Thank you. Very helpful!
