Animation from data points (arrays)

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.

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

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]



With Plots.jl you could do this very similarly to the Makie example, using the @animate macro.

1 Like

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.

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.

1 Like