# Sliders and plot together in one windows

**URL:** <https://discourse.julialang.org/t/sliders-and-plot-together-in-one-windows/50538>\
**Category:** Visualization\
**Created:** [November 21, 2020, 3:47pm UTC](https://discourse.julialang.org/t/sliders-and-plot-together-in-one-windows/50538 "2020-11-21T15:47:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomas\_Pevny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomas_pevny/32/25466_2.png) [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Post date:** [November 21, 2020, 3:47pm UTC](https://discourse.julialang.org/t/sliders-and-plot-together-in-one-windows/50538/1 "2020-11-21T15:47:02Z")

</div>

Hi,

I am preparing a lecture on Hypothesis testing for students and plan to go from the very basic, hopefully helping them understand the problems.

Last year, my notebook was in Jupyter with Interact package, which was a nightmare to set up. This year, I want to switch to Pluto. Currently, my biggest problem is that I cannot display sliders together with Plot. Specifically, I would like this

```julia
@bind μ Slider(-2:0.1:2; default=1, show_value=true)
@bind σ² Slider(0.001:0.1:2, default = 1,show_value = true)
@bind n Slider(2:1:1000, default = 1000, show_value = true)
p₁ = Normal(μ,σ²)
ts = [EqualVarianceTTest(rand(p₁,n), rand(p₁,n)).t for _ in 1:10000];
p = histogram(ts, normalized = true,alpha = 0.25)
plot!(p, μ - 5σ²:0.2σ²:μ + 5σ², x -> pdf(TDist(2n-2), x),label = "Student-T distribution")

```

to be rendered such that I will have sliders over the plot in one output.

I can do this my putting every slider to its own line and the plot afterwards, but if the notebook contains several of these blocks, I need to choose everytime a different name, which is a bit annoying.

Thanks for answers in advance.

Tomas

---

<div class="post-metadata">

**Author:** ![fonsp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fonsp/32/222349_2.png) [@fonsp](https://discourse.julialang.org/u/fonsp)\
**Post date:** [November 22, 2020, 12:09pm UTC](https://discourse.julialang.org/t/sliders-and-plot-together-in-one-windows/50538/2 "2020-11-22T12:09:29Z")

</div>

Hi!

Awesome to hear that you are using Pluto for your classroom! This is exactly what I am designing Pluto for, so please let me know what else comes up, and if you like we can take a look at your notebooks together: [fonsvdplas@gmail.com](mailto:fonsvdplas@gmail.com)

The way I see it, you mentioned two separate issues:

## 1. Combining sliders

You can combine the sliders into a single cell, have a look at the Interactivity sample notebook from the Pluto main menu to learn how. Unfortunately, you can _not_ also place the plot inside that cell: the sliders need to live in a different cell than the plot.

The reason is that **interactivity works through reactivity**. In your example, moving the first slider sets the global variable μ. Pluto finds which cells depend on μ, and runs those as a response. If both the slider and the plot are in the same cell, then _the cell responding to the change is also the cell that generates a new slider_. This would reset the slider to its initial state.

## 2. You need to choose new variable names

This is true, and it can be a bit annoying. The only tip I can give is to not name your variables: `x1`, `x2`, `x3`, but something more descriptive: `x_advection`, `x_diffusion`, `x_both`.

* * *

A main difference between Interact and Pluto’s `@bind` is that Interact controls _local variables_ (exist within one cell), while `@bind` controls _global variables_ (exist in all cells). I believe that the latter can be more intuitive, because it reuses the same reactivity paradigm for interactivity. But it does mean that converting Interact-based code to Pluto can be tricky.

---

<div class="post-metadata">

**Author:** ![Tomas\_Pevny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomas_pevny/32/25466_2.png) [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Post date:** [November 22, 2020, 1:16pm UTC](https://discourse.julialang.org/t/sliders-and-plot-together-in-one-windows/50538/3 "2020-11-22T13:16:01Z")

</div>

Hi Fons,

thanks for the answer. I understand your design decisions (I have seen your Juliacon talk) and I have expected that the problem with naming is not currently solvable, though it makes it a bit cumbersome. I have resolved the naming problem as you have said, although I have used the underscore notation because the variables were not that important.

Thanks for pointing me to the example of combining the sliders. It works very nicely. I was trying to use the same trick with plot the plot, and although the rendering was as I wanted, the interactivity was lost. I guess that this was caused by the fact that cell was not updated by the change. But I guess this is sufficient and cool.

Thanks a lot for help and of course for Pluto.
