# Makie: Animation via Node() works with text(), but not with scatter()

**URL:** https://discourse.julialang.org/t/makie-animation-via-node-works-with-text-but-not-with-scatter/28100
**Category:** Visualization
**Tags:** makie
**Created:** [August 28, 2019, 12:03pm UTC](https://discourse.julialang.org/t/makie-animation-via-node-works-with-text-but-not-with-scatter/28100 "2019-08-28T12:03:52Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Arjen\_Suijker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arjen_suijker/32/8213_2.png) [@Arjen\_Suijker](https://discourse.julialang.org/u/Arjen_Suijker)
#### Post date: [August 28, 2019, 12:03pm UTC](https://discourse.julialang.org/t/makie-animation-via-node-works-with-text-but-not-with-scatter/28100/1 "2019-08-28T12:03:52Z")

</div>

I have been struggling with this for days, I don’t know if this is a bug or if I’m just missing something.

I want to animate both text and and scatters based on real-time input. I’m using Node for this (Observables). This works fine for text, but not for scatter (or lines). I hope my code is understandable:

```julia
module Animate
export doAnimate
using Makie

scene = Scene(resolution = (500,500))
attrs = String[]
posX = []
posY = []

function doAnimate(woord,fitness)

    newPosX = rand(1:200)
    newPosY = rand(1:200)

    global attrs
    global posX
    global posY

    cur = 0
    for i = 1:length(attrs)
        if(attrs[i] == woord)
            cur = i
        end
    end

    if (cur>0)
        oldPosX = posX[cur][]
        oldPosY = posY[cur][]

        xStep = (newPosX - oldPosX) / 30
        yStep = (newPosY - oldPosY) / 30

        for i = 1:30

            push!(posX[cur], oldPosX + xStep * i)
            push!(posY[cur], oldPosY + yStep * i)

            sleep(1/30)

            display(scene)
        end

    else
        push!(posX, Node(0.0))
        push!(posY, Node(0.0))

        s = scatter!([posX[end]], [posX[end]], color = :blue)
        t = text!(scene, "fgdsg", position = (posX[end], posY[end]))

        push!(attrs, woord)
    end
  return

end

end

```

The problem lies with the following line:

```julia
s = scatter!([posX[end]], [posX[end]], color = :blue)

```

It gives me the following error:

```julia
ERROR: LoadError: MethodError: no method matching push!(::Annotations{...}, ::Array{String,1}, ::Tuple{Int64,Float64}; rotation=0.0, textsize=0.059999995f0, align=(:center, :top), color=:black, font="Dejavu Sans")

```

Anyone understands what’s going on?

---

<div class="post-metadata">

### Author: ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)
#### Post date: [August 29, 2019, 8:30am UTC](https://discourse.julialang.org/t/makie-animation-via-node-works-with-text-but-not-with-scatter/28100/2 "2019-08-29T08:30:49Z")

</div>

If you need `display` in your animation loop, you’re doing something wrong 😉  
I’m not sure I understand your code… Can you make a runnable example?  
Best without module & function definition and as simple as possible!

---

<div class="post-metadata">

### Author: ![Arjen\_Suijker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arjen_suijker/32/8213_2.png) [@Arjen\_Suijker](https://discourse.julialang.org/u/Arjen_Suijker)
#### Post date: [August 30, 2019, 2:25pm UTC](https://discourse.julialang.org/t/makie-animation-via-node-works-with-text-but-not-with-scatter/28100/3 "2019-08-30T14:25:43Z")

</div>

Thank you for your quick reply. I’m afraid that stripping it down further will obfuscate the problem. However, I have made it so that it runs as is:

```julia
using Makie
using Random

scene = Scene(resolution = (500,500))
attrs = String[]
posX = []
posY = []

function doAnimate(woord,fitness)

    newPosX = rand(1:200)
    newPosY = rand(1:200)

    global attrs
    global posX
    global posY

    cur = 0
    for i = 1:length(attrs)
        if(attrs[i] == woord)
            cur = i
        end
    end

    if (cur>0)
        oldPosX = posX[cur][]
        oldPosY = posY[cur][]

        xStep = (newPosX - oldPosX) / 30
        yStep = (newPosY - oldPosY) / 30

        for i = 1:30

            push!(posX[cur], oldPosX + xStep * i)
            push!(posY[cur], oldPosY + yStep * i)

            sleep(1/30)

            display(scene)
        end

    else
        push!(posX, Node(0.0))
        push!(posY, Node(0.0))

        println(woord)

        #s = scatter!([posX[end]], [posX[end]], color = :blue)
        t = text!(scene, "fgdsg", position = (posX[end], posY[end]))

        push!(attrs, woord)
    end
  return

end

for i = 1:20

    doAnimate(string(rand(1:5)),0)

    sleep(1)
end

```

If you uncomment the commented line, you’ll get an error that I really don’t understand. I expect there to appear scatters moving around the scene just like the text.

---

<div class="post-metadata">

### Author: ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)
#### Post date: [September 1, 2019, 12:30pm UTC](https://discourse.julialang.org/t/makie-animation-via-node-works-with-text-but-not-with-scatter/28100/4 "2019-09-01T12:30:39Z")

</div>

There are a lot of things I’d do differently… This should work:

```julia
using Makie
using Random

scene = Scene(resolution = (500,500), limits = FRect3D(Vec3f0(0), Vec3f0(150, 150, 0)))
words = Node(String[" "]) # Empty array of string doesn't work :( ... Need a better way for this!
positions = Node(Point2f0[Point2f0(0)])

function doAnimate(word, fitness)
    newpos = rand(Point2f0) .+ 1.0 .* 100
    cur = findfirst(isequal(word), words[])
    if cur !== nothing
        oldpos = positions[][cur]
        step = (newpos .- oldpos) ./ 30
        for i = 1:30
            isopen(scene) || break
            positions[][cur] = oldpos .+ step .* i
            positions[] = positions[]
            # update!(scene)
            sleep(1/30)
        end
    else
        println(word)
        push!(positions[], Point2f0(0.0))
        push!(words[], word)
        positions[] = positions[]
        words[] = words[]
        # update!(scene)
    end
  return
end

scatter!(positions, color = :blue, markersize = 5)
annotations!(words, positions)
display(scene)
for i = 1:20
    isopen(scene) || break
    doAnimate(string(rand(1:5)), 0)
    sleep(1)
end

```

---

<div class="post-metadata">

### Author: ![Arjen\_Suijker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arjen_suijker/32/8213_2.png) [@Arjen\_Suijker](https://discourse.julialang.org/u/Arjen_Suijker)
#### Post date: [September 2, 2019, 10:56am UTC](https://discourse.julialang.org/t/makie-animation-via-node-works-with-text-but-not-with-scatter/28100/5 "2019-09-02T10:56:09Z")

</div>

Wow, thanks for taking the time! I made it work with your method. I come from a sloppy JavaScript background, so getting used to Julia is quite hard.

Could you explain why in my version lines() worked while scatter() didn’t?

---

<div class="post-metadata">

### Author: ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)
#### Post date: [September 2, 2019, 12:21pm UTC](https://discourse.julialang.org/t/makie-animation-via-node-works-with-text-but-not-with-scatter/28100/6 "2019-09-02T12:21:16Z")

</div>

I didn’t look too closely, but I think you created something like: `[Node(number)]`, which doesn’t work… You need to supply an array, or `Node(array)`, but not `Array(node)`

---

<div class="post-metadata">

### Author: ![nantonel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nantonel/32/2889_2.png) [@nantonel](https://discourse.julialang.org/u/nantonel)
#### Post date: [October 14, 2021, 11:21am UTC](https://discourse.julialang.org/t/makie-animation-via-node-works-with-text-but-not-with-scatter/28100/7 "2021-10-14T11:21:29Z")

</div>

I’m posting here since the topic name is the same.

I’d like to update a matrix using `Node`. Although I manage to update text, I cannot see to update the matrix. Here is a MWE, similar to the [Appending data with Observables](https://makie.juliaplots.org/stable/documentation/animation/index.html#appending_data_with_observables)

```julia
using GLMakie
A = Node(ones(30,30))
time = Node(1)
fig, ax = heatmap(A, 
            axis = (title = @lift("t = $(round($time, digits = 1))"),)
           )

frames = 1:30

record(fig, "append_animation.mp4", frames;
        framerate = 30) do t
  time[] = t
  A[][t,t] += t
end

```

---

<div class="post-metadata">

### Author: ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)
#### Post date: [October 14, 2021, 11:48am UTC](https://discourse.julialang.org/t/makie-animation-via-node-works-with-text-but-not-with-scatter/28100/8 "2021-10-14T11:48:01Z")

</div>

> I’m posting here since the topic name is the same.

One should usually just open a new topic 😉

```julia
A[][t,t] += t

```

You’re not updating the Node, instead you update the matrix in-place…  
To make this work you need to call:

```julia
notify(A)

```

With GLMakie, you can also try the `Sampler` type, which allows to really just upload the indices you change to the gpu:

> <https://github.com/MakieOrg/Makie.jl/blob/6b71a7f0b60aa0573309a4f236b9d5c56c4d4cc8/GLMakie/test/glmakie_tests.jl#L32>

It’s not well tested, and may only work with image though… If it doesn’t work like intended with Heatmap, feel free to open an issue:

> **[Build software better, together](https://github.com/MakieOrg/Makie.jl/issues/new)**
>
> GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 420 million projects.

---

<div class="post-metadata">

### Author: ![nantonel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nantonel/32/2889_2.png) [@nantonel](https://discourse.julialang.org/u/nantonel)
#### Post date: [October 14, 2021, 12:39pm UTC](https://discourse.julialang.org/t/makie-animation-via-node-works-with-text-but-not-with-scatter/28100/9 "2021-10-14T12:39:24Z")

</div>

This works perfectly:

> [@sdanisch](#):
>
> `notify(A)`

Thank you! Haven’t tried `Sampler`, no GPU at the moment 😃
