# Need help with makie animation

**URL:** <https://discourse.julialang.org/t/need-help-with-makie-animation/112527>\
**Category:** Visualization\
**Tags:** question, makie\
**Created:** [April 4, 2024, 3:20pm UTC](https://discourse.julialang.org/t/need-help-with-makie-animation/112527 "2024-04-04T15:20:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![oddsen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oddsen/32/208238_2.png) [@oddsen](https://discourse.julialang.org/u/oddsen)\
**Post date:** [April 4, 2024, 3:20pm UTC](https://discourse.julialang.org/t/need-help-with-makie-animation/112527/1 "2024-04-04T15:20:30Z")

</div>

This is my code :

 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/a/ea1dbf6435e0948c8525eabba29a7cacf742ec4e.jpeg)

I want to create an animation or slide illustrating the movement of my points on a sphere as the variable ‘i’ increases from 1 to ‘Stop’. This will allow me to visualize the trajectory of my three points on the sphere. However, I’m not familiar with the process. Can anyone provide tips on how to achieve this?

Currently, my plot resembles this:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/a/8a79768da2dcae941344f85b62c5a41a00c0f6e1.jpeg)

And this is incorrect because it depicts the movement of my three points in a single picture, whereas I intend to spread it out across 35 pictures (as my ‘Stop’ value is defined as 35).

---

<div class="post-metadata">

**Author:** ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)\
**Post date:** [April 4, 2024, 3:54pm UTC](https://discourse.julialang.org/t/need-help-with-makie-animation/112527/2 "2024-04-04T15:54:56Z")

</div>

You should take a look at [Makie’s animation docs](https://docs.makie.org/dev/explanations/animation/)

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

```julia
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:

```julia
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

```
