I want to update a plot in Jupyter notebook by clicking a button. I’m using Makie and Interact. Here is a minimal example:
using Makie, AbstractPlotting, WGLMakie
using Interact
t=0:1e-3:1
y1 = sin.(2pi*10*t).*exp.(-t/0.1)
y2 = cos.(2pi*10*t).*exp.(-t/0.15)
scene = Scene(resolution = (500, 500))
lines!(scene, t, y1, scale_plot = true, color = :red, linestyle = :dash)
lines!(scene, t, y2, scale_plot = true, color = :blue, linestyle = :dashdotdot)
bt = Interact.button("Plot")
function update_plot(x)
y2 = randn(1001)
scene[2][1].val .= Point2f0.(t,y2);
axis = scene[Axis]
axis[:names, :axisnames] = ("t", "Yvalues")
AbstractPlotting.update_limits!(scene)
AbstractPlotting.update!(scene)
end
display(scene)
on(update_plot, bt)
display(bt)
The Ylabel is updated when I click the button, but the plot itself is not. If I run display(scene)
in a separate cell the plot is shown updated, but I would like to avoid duplicating the scene(the plot will actually be updated hundreds of times by the user via button click. What am I doing wrong? Thank you!