Fast animations

Hi, what would be the fastest way to generate animations or videos? I’ve been able to make animated gifs with @animateanimate but they take quite some time. Here’s the kind of stuff I’m doing:

data = Matrix(m.data)
X = data[:,1:3:end]
Y = data[:,2:3:end]
Z = data[:,3:3:end]
anim = @animate for i in 1:m.nframes
    Plots.scatter(X[i,:],Y[i,:],Z[i,:],
        legend=false,
        xlim=extrema(filter(!isnan,X)),
        ylim=extrema(filter(!isnan,Y)),
        zlim=extrema(filter(!isnan,Z)))
end
gif(anim,fps=60)

Output doesn’t need to be .gif, it can be .mov for instance. Thanks for your help! :slightly_smiling_face:

I would try Makie.jl?

1 Like

For your case I’d second @gdalle and say Makie’s record-function is the way to go.

If you don’t want to switch to Makie.jl, you could export images of your Plots.jl plots via savefig and use VideoIO.jl to generate a video out of the image seqence like so:

VideoIO.save(filename::String, imgstack::Array)

Do you need this high framerate?

Makie is well suited for animations using their Observable system:

using GLMakie

nframes = 300
data = rand(1000, nframes)

X = data[:,1:3:end]
Y = data[:,2:3:end]
Z = data[:,3:3:end]

frame = Observable(1)
point = @lift(Point3.(X[$frame, :], Y[$frame, :], Z[$frame, :]))

fig = Figure()
ax = Axis(
    fig[1,1]
)

scatter!(point)
fig

record(fig, "animation.gif", 1:nframes; framerate = 20) do iteration
    frame[] = iteration
end

Gives:
animation

2 Likes