# Simple animation with Makie

**URL:** <https://discourse.julialang.org/t/simple-animation-with-makie/109439>\
**Category:** General Usage\
**Tags:** makie\
**Created:** [January 30, 2024, 10:34am UTC](https://discourse.julialang.org/t/simple-animation-with-makie/109439 "2024-01-30T10:34:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gravlax](https://avatars.discourse-cdn.com/v4/letter/g/dbc845/32.png) [@Gravlax](https://discourse.julialang.org/u/Gravlax)\
**Post date:** [January 30, 2024, 10:34am UTC](https://discourse.julialang.org/t/simple-animation-with-makie/109439/1 "2024-01-30T10:34:32Z")

</div>

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?

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

```

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [January 30, 2024, 11:38am UTC](https://discourse.julialang.org/t/simple-animation-with-makie/109439/2 "2024-01-30T11:38:02Z")

</div>

You’ll get the closest with the new [SpecApi](https://docs.makie.org/stable/explanations/specapi/):

```julia
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/](https://docs.makie.org/stable/explanations/animation/)

---

<div class="post-metadata">

**Author:** ![Gravlax](https://avatars.discourse-cdn.com/v4/letter/g/dbc845/32.png) [@Gravlax](https://discourse.julialang.org/u/Gravlax)\
**Post date:** [January 30, 2024, 1:44pm UTC](https://discourse.julialang.org/t/simple-animation-with-makie/109439/3 "2024-01-30T13:44:54Z")

</div>

Thanks, very nice new feature!  
How easy would it be to incorporate subplots like in the example below?

```julia
using Plots
let
    anim = @animate for it=1:10
        p1 = plot(title="Animation 1")
        p1 = plot(1:10, (1:10).^2, label=:none)
        p1 = scatter!([it], [it^2], label=:none)
        p2 = plot(title="Animation 2")
        p2 = plot(1:10, (1:10).^-2, label=:none)
        p2 = scatter!([it], [it^-2], label=:none)
        plot(p1, p2)
    end
    gif(anim, "anim_MWE.gif", fps = 5)
end

```

I’ve tried adding `fig[1, 1]` in the `Axis` call, without success.

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [January 30, 2024, 3:25pm UTC](https://discourse.julialang.org/t/simple-animation-with-makie/109439/4 "2024-01-30T15:25:18Z")

</div>

Like this:

```julia
let
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
        ax1 = S.Axis(title="Animation", plots=[
            S.Lines(1:10, (1:10) .^ 2),
            S.Scatter([it], [it^2],)
        ])
        ax2 = S.Axis(title="Animation 2", plots=[
            S.Lines(1:10, (1:10) .^ 2),
            S.Scatter([it], [it^2],)
        ])
        spec[1] = S.GridLayout(ax1, ax2)
    end
end

end

```

There are a few examples in the linked docs about how to create layouts

---

<div class="post-metadata">

**Author:** ![tduretz](https://avatars.discourse-cdn.com/v4/letter/t/bcef8e/32.png) [@tduretz](https://discourse.julialang.org/u/tduretz)\
**Post date:** [June 21, 2025, 1:13pm UTC](https://discourse.julialang.org/t/simple-animation-with-makie/109439/5 "2025-06-21T13:13:56Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [June 21, 2025, 2:00pm UTC](https://discourse.julialang.org/t/simple-animation-with-makie/109439/6 "2025-06-21T14:00:15Z")

</div>

You should make a new post explaining what you want to do and what you have tried so far and what the problem right now is.

---

<div class="post-metadata">

**Author:** ![tduretz](https://avatars.discourse-cdn.com/v4/letter/t/bcef8e/32.png) [@tduretz](https://discourse.julialang.org/u/tduretz)\
**Post date:** [June 21, 2025, 2:16pm UTC](https://discourse.julialang.org/t/simple-animation-with-makie/109439/7 "2025-06-21T14:16:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [June 21, 2025, 2:31pm UTC](https://discourse.julialang.org/t/simple-animation-with-makie/109439/8 "2025-06-21T14:31:23Z")

</div>

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:

> **[SpecApi | Makie](https://docs.makie.org/stable/explanations/specapi#SpecApi)**
>
> Create impressive data visualizations with Makie, the plotting ecosystem for the Julia language. Build aesthetic plots with beautiful customizable themes, control every last detail of publication quality vector graphics, assemble complex layouts and...

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [June 21, 2025, 4:53pm UTC](https://discourse.julialang.org/t/simple-animation-with-makie/109439/9 "2025-06-21T16:53:11Z")

</div>

A simpler way is just

```julia
fig,ax,plt = lines(1:10, (1:10).^2)
it = Observable(1)
scatter!((@lift ($it, $it^2)))
Record(fig, 1:10) do _it
	it[] = _it
end

```
