# Animation from data points (arrays)

**URL:** <https://discourse.julialang.org/t/animation-from-data-points-arrays/40642>\
**Category:** Visualization\
**Tags:** question\
**Created:** [June 3, 2020, 2:33am UTC](https://discourse.julialang.org/t/animation-from-data-points-arrays/40642 "2020-06-03T02:33:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joey](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@Joey](https://discourse.julialang.org/u/Joey)\
**Post date:** [June 3, 2020, 2:33am UTC](https://discourse.julialang.org/t/animation-from-data-points-arrays/40642/1 "2020-06-03T02:33:08Z")

</div>

Hello, everyone.

I recently switched from MATLAB to Julia, and I do not know a lot of stuff about plotting in Julia. It is a really simple problem yet unclear to me: I need to build a 3d animation out of a set of data points. For instance, I have an array set with coordinates from 3d points, plus an array with sets of displacements associated to these points, let’s say 50 sets of displacements… I need to do an amination with each frame being the original coordinates + a set of displacements. I also need to connect these points two by two (lines) in each frame. I’d appreciate if anybody could help me out.

---

<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 3, 2020, 6:12am UTC](https://discourse.julialang.org/t/animation-from-data-points-arrays/40642/2 "2020-06-03T06:12:51Z")

</div>

Here’s one bare-bones version to get you started with `Makie.jl`:

```julia
using Makie
using AbstractPlotting: px

npoints = 50
original_points = rand(Point3f0, npoints) .* 50
points = Node(original_points)
nframes = 100
displacements = rand(Point3f0, npoints, nframes)

scene = scatter(points, markersize = 10px, resolution = (500, 500), scale = false)
linesegments!(scene, points)

record(scene, "test.gif", 1:nframes, framerate = 20) do i
    # update points observable, scatter and linesegments automatically update
    points[] = original_points .+ displacements[:, i]
end

```

![test](https://global.discourse-cdn.com/julialang/original/3X/f/2/f2813e146410c28b4f0ba3404026c625b2f7d24b.gif)

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [June 3, 2020, 6:54am UTC](https://discourse.julialang.org/t/animation-from-data-points-arrays/40642/3 "2020-06-03T06:54:15Z")

</div>

With Plots.jl you could do this very similarly to the Makie example, using the @animate macro. [Animations · Plots](https://docs.juliaplots.org/latest/animations/)

---

<div class="post-metadata">

**Author:** ![Joey](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@Joey](https://discourse.julialang.org/u/Joey)\
**Post date:** [June 3, 2020, 12:18pm UTC](https://discourse.julialang.org/t/animation-from-data-points-arrays/40642/4 "2020-06-03T12:18:40Z")

</div>

Thank you! This works fine here. I’ve been trying to use Pltots.jl, so I don’t need to import lots of packages into my modules. But this works just fine.

---

<div class="post-metadata">

**Author:** ![Joey](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@Joey](https://discourse.julialang.org/u/Joey)\
**Post date:** [June 3, 2020, 12:24pm UTC](https://discourse.julialang.org/t/animation-from-data-points-arrays/40642/5 "2020-06-03T12:24:48Z")

</div>

Yes! I’m getting a bit familiar with this macro, even though I can’t find much about it on this documentation. This macro seems to have a lot of features, but they are not quite explored, I guess. Quick question: how do I save the gif to a specific folder? I’m having a hard time trying to get it from the default location. Thanks in advance.
