# Using slider control with multiple traces

**URL:** <https://community.plotly.com/t/using-slider-control-with-multiple-traces/7074>\
**Category:** 📊 Plotly Python\
**Created:** [November 29, 2017, 4:42pm UTC](https://community.plotly.com/t/using-slider-control-with-multiple-traces/7074 "2017-11-29T16:42:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chch](https://avatars.discourse-cdn.com/v4/letter/c/a5b964/32.png) [@chch](https://community.plotly.com/u/chch)\
**Post date:** [November 29, 2017, 4:42pm UTC](https://community.plotly.com/t/using-slider-control-with-multiple-traces/7074/1 "2017-11-29T16:42:40Z")

</div>

I’d like to add the slider control to my **plotly** graph ([https://i.stack.imgur.com/BzAr3.png](https://i.stack.imgur.com/BzAr3.png)) to control all elements simultaneously.

I can easily add slider control to graph with only one line. In this case I put a list of plots (in form of dicts) into **data** variable:

> _plotly.graph\_objs.Figure (**data = [plot1,plot2]**, layout = layout)_

And it’s work quite good.

* * *

But in order to plot multiple lines on the same graph, I have to put list of lists with plots into data variable _( have I ? )_:

> _plotly.graph\_objs.Figure (**data = [[plot1.1, plot2.1], [plot1.2, plot2.2]]**, layout = layout)_

But plot.ly still expects the list of dicts.

> _Entry should subclass dict._

* * *

Are there any way to control multiple elements simultaneously using one slider control?

```
import plotly
import plotly.plotly as py
import numpy as np

plotly.offline.init_notebook_mode()

exp = 2.71

N = 3

x_start = -N
x_end = N
dx = 0.1

y_start = -N
y_end = N
dy = 0.1

x_axis = np.arange(x_start, x_end, dx)
y_axis = np.arange(y_start, y_end, dy)

def pit(offset, x):
    pit1 = []
    for position in x:
        pit1.append(1 - exp**(-36 * (position - offset)**2))
    return pit1

def v_x(x):
    vx = exp**(-x**2)
    return vx

def v_y(x):
    vy = 0.5 * exp**(-x**2)
    return vy

def density(vx, vy):
    den = []
    for v1 in vx:
        row = []
        for v2 in vy:
            row.append(v1 * v2)
        den.append(row)
    return den

vx = v_x(x_axis)
vy = v_y(y_axis)

den = density(vx, vy)

def contour(step=None):
    return dict(
        type='contour',
        z=den,
        colorscale=[[0, 'rgb(255,255,255)'], [1, 'rgb(49,163,84)']],
        x=x_axis,
        y=y_axis,
    )

def vy_projection(step):
    return dict(
        visible=True,
        type='scatter',
        name=str(step),
        marker=dict(color='rgb(255,0,0)'),
        yaxis='y2',
        x=x_axis,
        y=vx * pit(step, x_axis)
    )

def vx_projection(step):
    return dict(
        visible=True,
        type='scatter',
        name=str(step),
        marker=dict(color='rgb(255,0,255)'),
        xaxis='x2',
        x=vy,
        y=y_axis
    )

trace1 = [
    [vy_projection(step), vx_projection(step)]
    for step in np.arange(-3, 3, 0.5)]

for plot in trace1[-1]:
    plot['visible'] = True

steps = []
for i in range(len(trace1)):
    step = dict(
        method='restyle',
        args=['visible', [False] * len(trace1)],
    )
    step['args'][1][i] = True
    steps.append(step)

sliders = [dict(
    active=10,
    currentvalue={"prefix": "Step: "},
    pad={"t": len(trace1)},
    steps=steps
)]

layout = dict(
    autosize=False,
    width=500,
    height=500,
    sliders=sliders,
    xaxis=dict(
        range=[-3, 3],
    ),
    xaxis2=dict(
        domain=[0.9, 1],
        showgrid=False,
        zeroline=False,
    ),
    yaxis=dict(
        range=[-3, 3],
    ),
    yaxis2=dict(
        domain=[0.9, 1],
        showgrid=False,
        zeroline=False,
    )

)
data = trace1[0]
fig = go.Figure(data=data, layout=layout)

# plotly.offline.plot(fig, filename='manipulate.html')
plotly.offline.iplot(fig)

```

---

<div class="post-metadata">

**Author:** ![joseph.vergel](https://avatars.discourse-cdn.com/v4/letter/j/e36b37/32.png) [@joseph.vergel](https://community.plotly.com/u/joseph.vergel)\
**Post date:** [April 9, 2018, 5:13pm UTC](https://community.plotly.com/t/using-slider-control-with-multiple-traces/7074/2 "2018-04-09T17:13:03Z")

</div>

I have the same problem. Can somebody helps us?

---

<div class="post-metadata">

**Author:** ![chch](https://avatars.discourse-cdn.com/v4/letter/c/a5b964/32.png) [@chch](https://community.plotly.com/u/chch)\
**Post date:** [April 10, 2018, 7:27am UTC](https://community.plotly.com/t/using-slider-control-with-multiple-traces/7074/3 "2018-04-10T07:27:22Z")

</div>

The problem has been solved:

> <https://stackoverflow.com/questions/47554585/plot-ly-using-slider-control-with-multiple-plots/47558057#47558057>
