# Makie: animation becomes slow after redrawing surface about 25 times

**URL:** <https://discourse.julialang.org/t/makie-animation-becomes-slow-after-redrawing-surface-about-25-times/45582>\
**Category:** Performance\
**Created:** [August 26, 2020, 5:38pm UTC](https://discourse.julialang.org/t/makie-animation-becomes-slow-after-redrawing-surface-about-25-times/45582 "2020-08-26T17:38:03Z")\
**Posts on this page:** 1\
**Showing post:** 6

<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:** [August 27, 2020, 4:07pm UTC](https://discourse.julialang.org/t/makie-animation-becomes-slow-after-redrawing-surface-about-25-times/45582/6 "2020-08-27T16:07:24Z")

</div>

I think your confusion comes from this line

```julia
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:

```julia
# 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:

```julia
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.

---

_[View the full topic](https://discourse.julialang.org/t/makie-animation-becomes-slow-after-redrawing-surface-about-25-times/45582)._
