Displaying figure while recording animation using Makie.record

I am able to record an animation of a figure in Makie using record. I can check if the figure is correctly updated in the animation by playing the movie file after the recording finishes. However, animation creation usually takes time because it requires the whole iteration. So, I would like to monitor the evolution of the figure while the animation is being generated.

I thought this can be easily done by putting display(fig) in the record loop, but it didn’t work. Here is an example:

using CairoMakie

xs = range(0, 2π, 100)
fig = Figure()
record(fig, "test_record.mp4", 0:5) do n
    fig[1,1] = Axis(fig, limits=(0,2π,-1,1))
    lines!(xs, sin.(n .* xs))

    # display(fig)
    # The above line
    # - either crashes the integrated REPL when runs in VScode,
    # - or does not update the figure when runs in terminal.

How can I display the evolution of a figure while the evolution is being recorded?

Is using GLMakie an option? There, you can put disolay(fig) before the record block and it will show the updated figure in an extra window (make sure to call Makie.inline!(false) to not use the plot plane.)

Also check out the Makie tutorial on animations. There are efficient ways to update plotting data using Observables. With that, making videos is often very fast (in my cases easily 10 to 100 times faster than naive re plotting.)


1 Like