# How to create an animation based on t, x, y and z data?

**URL:** <https://discourse.julialang.org/t/how-to-create-an-animation-based-on-t-x-y-and-z-data/25672>\
**Category:** General Usage\
**Tags:** plotting, plots, animations\
**Created:** [June 26, 2019, 2:06am UTC](https://discourse.julialang.org/t/how-to-create-an-animation-based-on-t-x-y-and-z-data/25672 "2019-06-26T02:06:57Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Sevi](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@Sevi](https://discourse.julialang.org/u/Sevi)\
**Post date:** [November 5, 2023, 2:45pm UTC](https://discourse.julialang.org/t/how-to-create-an-animation-based-on-t-x-y-and-z-data/25672/8 "2023-11-05T14:45:24Z")

</div>

Welcome to the forum @CM1 !

It’s probably slower since the combined plot has to be recreated every step of the animation, but this worked for me:

```julia
using Plots

N = 200

u1 = 20*rand(3, N)
u2 = 15*ones(3, N)

plt1 = plot3d(
    1,
    xlim = (-30, 30),
    ylim = (-30, 30),
    zlim = (0, 60),
    title = ["Some trajectory"],
    legend = false,
    marker = 2,
)

plt2 = plot3d(
    1,
    xlim = (-30, 30),
    ylim = (-30, 30),
    zlim = (0, 60),
    title = ["Other trajectory"],
    legend = false,
    marker = 2,
)

@gif for i in range(1, size(u1, 2))
    push!(plt1, u1[:, i]...)
    push!(plt2, u2[:, i]...)
    plot(plt1, plt2)
end every 10

```

The docstring of `plot` mentions this about extracting subplots, but I couldn’t get it to work in the intended way (creating a new plot seems to remove the previously drawn points):

```julia
help?> plot

...

  Extract a subplot from an existing plot.

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> p1, p2 = plot(1:2), plot(10:20)
  julia> pl = plot(p1, p2) # plot containing 2 subplots
  
  julia> plot(pl.subplots[1]) # extract 1st subplot as a standalone plot
  julia> plot(pl.subplots[2]) # extract 2nd subplot as a standalone plot

```

---

_[View the full topic](https://discourse.julialang.org/t/how-to-create-an-animation-based-on-t-x-y-and-z-data/25672)._
