Refreshing a WGLMakie plot in realtime in jupyter notebook


The concept is just like the above picture (a Mathematica notebook). The use case is monitoring in realtime a field in numerical evolution. Is it possible using WGLMakie in jupyter notebook? Or other alternative suggestions?

Yes, see e.g: Animations | Makie
Of course you won’t need the record.

Thanks. I think you mean the Animating a plot “live” section:

because the record is needed otherwise.
So I copied the following code from there:

using WGLMakie

points = Observable(Point2f[randn(2)])

fig, ax = scatter(points)
limits!(ax, -4, 4, -4, 4)

fps = 60
nframes = 120

for i = 1:nframes
    new_point = Point2f(randn(2))
    points[] = push!(points[], new_point)
    sleep(1/fps) # refreshes the display!
end

while changed GLMakie to WGLMakie. But nothing happened in the jupyter notebook. No plot could be seen.
GLMakie just works well, refreshing the plot in realtime in an independent window. But as I said in the OP, what I need is a plot embedded in jupyter notebook that can be refreshed.

You need to either display or return the plot from the cell somehow. E.g. here’s a little example I made that does the same thing as your Mathematica snippet:

Note: making this example was a bit of a pain in the ass for me, and I ran into lots of weird buggy behaviour and I have no idea if it was firefox’s fault, WGLMakie’s fault, or Jupyter’s fault.

1 Like

Many thanks! Your method is definitely working in jupyter with a web browser, but it is not working in vs-code. Any solutions?

What are you doing with VSCode exactly?
VSCode notebooks aren’t supported yet.
Otherwise, you need an explicit display(figure) call, if you dont have cells.

Just using vs-code to run jupyter notebooks doing numerical simulation. On some cloud platforms, there is no option to run jupyter with a web browser, so only vs-code can be used. You can have a look here:

Thanks.

They will need to explicitly support Bonito.jl, e.g. like JuliaHub’s cloud VSCode IDE.
That’s because they have to proxy through the Websocket connection that Bonito needs to render + update the WGLMakie plots.

1 Like