Makie: animation becomes slow after redrawing surface about 25 times

I think your confusion comes from this line

glacier = Makie.surface!(scene, X, Y, H_v)

The mutating plotting functions like plot!(scene, ... return the scene, not the plot object created (bit weird, but that’s how it is).

You are currently adding a new surface to the scene each frame. That’s super slow.

Instead, you need to update an Observable or Node (same thing) that contains the plotted data. This will cause an update of the plot automatically. There are two ways to do that:

Either you create the Node first, plot it, then update it:

# create the node
data = Node(rand(10, 10))
# plot it
surface(1:10, 1:10, data)
# update it
data[] = rand(10, 10)
# plot updates automatically

Or you plot normal data, it gets wrapped in a Node automatically internally, then you update that internal node by accessing it via index notation. In a surface, the height matrix is the third argument, so this should work:

data = rand(10, 10)
# plot the data
scene = surface(1:10, 1:10, data)
# extract the plot object from the scene (last added plot)
actual_surface_plot = scene[end]
# get the internal node for the height matrix
internal_data_node = actual_surface_plot[3]
# update it
internal_data_node[] = rand(10, 10)
# plot updates automatically

So in your record loop, the only thing you need to do is the node update, the rest is automatic.

6 Likes