Need help with makie animation

You should take a look at Makie’s animation docs

In this case, you can update the contents of a single scatter plot directly, instead of re-plotting.

fig1, ax1, plt1 = mesh(...)
data_PSO = ...
moving_scatter_plot = scatter!(ax1, Point3f.(data_PSO[1]); markersize = 10, color = :blue)

record(fig1, "animation.gif", 1:Stop; framerate = 10) do i
    moving_scatter_plot[1][] = Point3f.(data_PSO[i])
    if i == Stop
        moving_scatter_plot.markersize = 20
        moving_scatter_plot.color = :red
    end
end

This should give you a GIF saved to animation.gif!

For more complex animations, the better way to handle this is through observables:

fig1, ax1, plt1 = mesh(...)
data_PSO = ...
# new line
data_points = Observable(Point3f.(data_PSO[1]))
moving_scatter_plot = scatter!(ax1, data_points; markersize = 10, color = :blue)

record(fig1, "animation.gif", 1:Stop; framerate = 10) do i
    data_points[] = Point3f.(data_PSO[i])
    if i == Stop
        moving_scatter_plot.markersize = 20
        moving_scatter_plot.color = :red
    end
end
1 Like