I have a function that generates plots in Makie. I want to compute a bunch of these plots and turn it into a gif.
The data for these plots is usually difficult to compute, so maybe at best I can compute it once and save it as some arrays. Or maybe I can save an array of figures and then animate it later.
So I am trying something to the extent of:
using CairoMakie
using Makie
using ImageMagick
xs = [ [i for i in 1:j] for j in 1:10 ]
ys = [ [1 for i in 1:j] for j in 1:10 ]
fig = CairoMakie.scatter(xs[1], ys[1] )
record(fig, "testGif.gif", 1:10; framerate=5) do t
fig = CairoMakie.scatter(xs[t], ys[t] )
end
But this produces a gif which only shows the first plot and does not change over time.
How can I produce a gif given some array of inputs to make an animated scatter plot? (Or alternatively if I had an array of plots, produce a gif?)
Many Makie functions, including the animation functions, often work better if provided with an explicit Figure() and Axis() to make frames from, instead of the implied, sometimes incomplete objects that are returned automatically from standalone plot functions like scatter(). So make a Figure and an Axis, and plot with scatter!(), since scatter!() will add to the Figure():
using CairoMakie
using Makie
using ImageMagick
xs = [ [i for i in 1:j] for j in 1:10 ]
ys = [ [i for i in 1:j] for j in 1:10 ]
fig = Figure()
ax = Axis(fig[1, 1])
record(fig, "testGif.gif", 1:10; framerate=5) do t
# you can put `empty!(ax)` here to wipe previous frame if wanted
scatter!(ax, xs[t], ys[t])
end