MWE plot with slider

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

Have you looked at Interact.jl? They provide plenty of example notebooks as part of the package.

I still need to add this to the official examples & documentation:
https://github.com/JuliaPlots/Makie.jl/blob/master/examples/interactive_examples.jl#L124

2 Likes

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

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

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

Hi,

I got it to work!!

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

@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.

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