I would like to generate a gif (or mkv) from a loop within which a figure is created at each iteration. Most Makie example I saw first create a figure, then modify it in an iteration. Could someone help me getting this Plots.jl MWE into a Makie one?
using Plots
let
anim = @animate for it=1:10
p = plot(title="Animation")
p = plot(1:10, (1:10).^2, label=:none)
p = scatter!([it], [it^2], label=:none)
end
gif(anim, "anim_MWE.gif", fps = 5)
end
using GLMakie
import Makie.SpecApi as S
let
fig, _, spec = plot(S.GridLayout()) # create empty spec plot
record(fig, "anim_MWE.gif", 1:10) do it
# update the spec
spec[1] = S.GridLayout(S.Axis(title="Animation", plots=[
S.Lines(1:10, (1:10).^2),
S.Scatter([it], [it^2], )
]))
end
end
It’s still a bit cumbersome in comparison, but could be made nicer for such animations.
Otherwise, for the old fashioned approach, I’d have a look at the docs: https://docs.makie.org/stable/explanations/animation/
I would like to ask if this is still the preferred way for doing this, or did things change over time?
I have given a try recently by I did not mange to get things to work. Thanks !
Oh sorry, I didn’t want to make a new post to ask for the same thing again. I was just curious to know if the API (SpecApi) changed in the meanwhile. I know that things are moving fast on your side and I thought that the way to create gifs using a loop may have evolved, please forget about my question.
You definitely can still do it that way, and if its the right way depends heavily on what youre doing.
You can take a look at the documentation for more infos: