# Animation keeps changing xlims ylims

**URL:** <https://discourse.julialang.org/t/animation-keeps-changing-xlims-ylims/131181>\
**Category:** New to Julia\
**Tags:** plots, recipe\
**Created:** [July 29, 2025, 6:12pm UTC](https://discourse.julialang.org/t/animation-keeps-changing-xlims-ylims/131181 "2025-07-29T18:12:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leibniz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leibniz/32/217959_2.png) [@Leibniz](https://discourse.julialang.org/u/Leibniz)\
**Post date:** [July 29, 2025, 6:12pm UTC](https://discourse.julialang.org/t/animation-keeps-changing-xlims-ylims/131181/1 "2025-07-29T18:12:50Z")

</div>

Greetings,

I have been struggling for hours to create an animation (particles in a box) where the xlims and ylims of the plot window remain fixed during the run.

```julia
@userplot SystemPlot  

@recipe function f(sp::SystemPlot)
    
   # Data frame holding x and y coordinates of N particles.
    frame_data = sp.args[1] # Index necessary because sp.args is a tuple.

    # Some attributes because particles are plotted as filled circles.
    radius = get(plotattributes, :radius, 0.5)       
    cos_theta = get(plotattributes, :cos_theta, nothing)
    sin_theta = get(plotattributes, :sin_theta, nothing)

    # Axis limits. They should remain fixed!
    xlims --> get(plotattributes, :xlims, nothing)
    ylims --> get(plotattributes, :ylims, nothing)
    
    aspect_ratio --> :equal
    legend --> false
    xlabel --> "x"
    ylabel --> "y"
    title --> "Frame $(frame_data.Frame[1])"

    for i in 1:nrow(frame_data)

        # some function to create circle shapes.
        x, y = draw_circle(frame_data.x[i], frame_data.y[i], radius, cos_theta, sin_theta)  
        shape = Shape(x, y)
        
        @series begin
            seriestype := :shape
            fillcolor := :blue
            alpha := 0.5
            linecolor := :black
            shape
         end
    end

```

But if I call this thing with

```julia
    x_lims = # some given tupel, e.g., (0,10)
    y_lims = # some given tupel, e.g., (0,10)

    anim = @animate for idx in frame_idx
        frame_data = frames[idx]
        systemplot(frame_data; 
                   cos_theta=cos_theta, 
                   sin_theta=sin_theta, 
                   radius=radius, 
                   xlims=x_lims, 
                   ylims=y_lims)  
    end

```

the xlims and ylims of the resulting plot window change from frame to frame.  
What am I doing wrong? It looks like the recipe does not properly process the limits.

Regards!

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [July 29, 2025, 6:25pm UTC](https://discourse.julialang.org/t/animation-keeps-changing-xlims-ylims/131181/2 "2025-07-29T18:25:50Z")

</div>

> [@Leibniz](#):
>
> ```julia-auto
> # Axis limits. They should remain fixed!
> xlims --> get(plotattributes, :xlims, nothing)
> ylims --> get(plotattributes, :ylims, nothing)
> 
> ```

You don’t need these two lines, this behavior should be the default?

---

<div class="post-metadata">

**Author:** ![Leibniz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leibniz/32/217959_2.png) [@Leibniz](https://discourse.julialang.org/u/Leibniz)\
**Post date:** [July 29, 2025, 6:31pm UTC](https://discourse.julialang.org/t/animation-keeps-changing-xlims-ylims/131181/3 "2025-07-29T18:31:05Z")

</div>

I see, did not know.  
I deleted them, but the issue remains.
