# MWE plot with slider

**URL:** <https://discourse.julialang.org/t/mwe-plot-with-slider/15876>\
**Category:** New to Julia\
**Tags:** plotting, reactiveprogramming\
**Created:** [October 4, 2018, 1:08pm UTC](https://discourse.julialang.org/t/mwe-plot-with-slider/15876 "2018-10-04T13:08:28Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [October 4, 2018, 1:08pm UTC](https://discourse.julialang.org/t/mwe-plot-with-slider/15876/1 "2018-10-04T13:08:28Z")

</div>

Hi,

I would like to find a MWE showing a slider which controls the plot behaviour, say, of a segment, like the coordinates of one of the two points.

I looked at Makie, but could not find a simple example.

Can someone provide it?

I need it to do a show of a real-time simulation.

Tahnk you for your help,

Bests

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [October 4, 2018, 1:20pm UTC](https://discourse.julialang.org/t/mwe-plot-with-slider/15876/2 "2018-10-04T13:20:43Z")

</div>

Have you looked at [Interact.jl](https://github.com/JuliaGizmos/Interact.jl)? They provide plenty of example notebooks as part of the package.

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [October 4, 2018, 2:23pm UTC](https://discourse.julialang.org/t/mwe-plot-with-slider/15876/3 "2018-10-04T14:23:18Z")

</div>

I still need to add this to the official examples & documentation:  
[https://github.com/JuliaPlots/Makie.jl/blob/master/examples/interactive\_examples.jl#L124](https://github.com/JuliaPlots/Makie.jl/blob/master/examples/interactive_examples.jl#L124)

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [October 4, 2018, 6:49pm UTC](https://discourse.julialang.org/t/mwe-plot-with-slider/15876/4 "2018-10-04T18:49:49Z")

</div>

I found a lot of good things there! Thank you.

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [October 4, 2018, 7:10pm UTC](https://discourse.julialang.org/t/mwe-plot-with-slider/15876/5 "2018-10-04T19:10:24Z")

</div>

Thank you to both of you!

I made some progress.

I want to solve an SDE which evolves in time and the user can interact with the parameters of the problem. It is a bit similar to the following apart from the fact that it does not work… Hence, I would need a last push to complete my simulation…

I would like `timer_sde` to be updated and plotted every `0.1s` and I would like the widget to feed back `J,sigma,...` to the stepper

```julia
using Plots, Interact
N = 10
timer_sde = Observable(rand(N))

function step!(x,iter,sigma,dt, J)
    for ii=1:iter
        @. x = x .+ (-x .+ J .* sum(x)) .* dt + (sigma) .* sqrt(dt) .* randn(length(x))
    end
end

@async while true
    sleep(0.1)
    step!(timer_sde,100,0.1,0.1, 0.1)
end

@manipulate for sigma = 0:0.1:4, J = 0:0.1:5, y = timer_sde
        plot(y)    
end

```

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [October 5, 2018, 7:17am UTC](https://discourse.julialang.org/t/mwe-plot-with-slider/15876/6 "2018-10-05T07:17:47Z")

</div>

Hi,

I got it to work!!

```julia
using Interact, GR, Statistics
N = 200
x = rand(N)
timer_sde = Observable(0.0)

function stepp!(x,iter,dt::Float64,sigma = 0.1,J = 1.0)
    for ii=1:iter
        x .= x .+ (-x .+ J .* mean(x)) .* dt .+ (sigma) .* sqrt(dt) .* randn(N)
    end
end

@async while true
    sleep(0.02)
    timer_sde[] = timer_sde[] + 1
end

# gr(size=(1000,300), html_output_format=:png)
@manipulate for sigma = 0:0.1:1, J = 0:0.1:1, t = timer_sde
        stepp!(x,10,0.1,sigma, J);
        GR.plot(x,ylim=(-2,2),size=(1000,300),xlabel="N")  
end

```

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [October 5, 2018, 8:08am UTC](https://discourse.julialang.org/t/mwe-plot-with-slider/15876/7 "2018-10-05T08:08:24Z")

</div>

@sdanisch

Would it be easy to port it to `Makie` so it runs in a window? Currently, I have to use IJulia and I don’t want the people to see the code.

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [July 9, 2022, 6:50am UTC](https://discourse.julialang.org/t/mwe-plot-with-slider/15876/8 "2022-07-09T06:50:06Z")

</div>

How about Pluto Notebooks? it runs on localhost, not on internet.
