# CairoMakie: how to set appropriate animation margins?

**URL:** https://discourse.julialang.org/t/cairomakie-how-to-set-appropriate-animation-margins/130049
**Category:** Visualization
**Tags:** question, makie
**Created:** [June 20, 2025, 2:56am UTC](https://discourse.julialang.org/t/cairomakie-how-to-set-appropriate-animation-margins/130049 "2025-06-20T02:56:27Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![fusion809](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fusion809/32/6080_2.png) [@fusion809](https://discourse.julialang.org/u/fusion809)
#### Post date: [June 20, 2025, 2:56am UTC](https://discourse.julialang.org/t/cairomakie-how-to-set-appropriate-animation-margins/130049/1 "2025-06-20T02:56:27Z")

</div>

I created the below animation of the elastic pendulum using CairoMakie and [this code](https://github.com/fusion809/julia-scripts/blob/master/ODEs/Generalized/elasticPendulum.jl).

My only qualm with it is the plot margins; they are too wide. I would like the Cartesian plane shown to span most of the animation window, not like 20% of it. How do I address this issue? I have tried to address this by setting the x and y limits and resolution, but these don’t seem to actually address this issue.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [June 20, 2025, 3:19am UTC](https://discourse.julialang.org/t/cairomakie-how-to-set-appropriate-animation-margins/130049/2 "2025-06-20T03:19:03Z")

</div>

```julia
    resize_to_layout!(fig)

```

try remove this?

---

<div class="post-metadata">

### Author: ![fusion809](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fusion809/32/6080_2.png) [@fusion809](https://discourse.julialang.org/u/fusion809)
#### Post date: [June 20, 2025, 3:39am UTC](https://discourse.julialang.org/t/cairomakie-how-to-set-appropriate-animation-margins/130049/3 "2025-06-20T03:39:02Z")

</div>

Sure, but I added it to fix this issue. Removing it leads to this animation. I don’t think there’s any difference.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [June 20, 2025, 4:29am UTC](https://discourse.julialang.org/t/cairomakie-how-to-set-appropriate-animation-margins/130049/4 "2025-06-20T04:29:57Z")

</div>

oh, `aspect = DataAspect()`, I guess this is the issue, try to remove it or set it to something else (like `1.0`).

I mean it really depends on what you want, because your axies size are quite different

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [June 20, 2025, 5:08am UTC](https://discourse.julialang.org/t/cairomakie-how-to-set-appropriate-animation-margins/130049/5 "2025-06-20T05:08:28Z")

</div>

You can try `autolimitaspect = 1` instead which will try to increase the limits to reach that aspect ratio. If you get a stack overflow because of layout cycles with that then fix the tick spacing with `tight_ticklabel_spacing!(ax)`
