# How to use Observable to Update Multiple Updates to a GLMakie Animation

**URL:** <https://discourse.julialang.org/t/how-to-use-observable-to-update-multiple-updates-to-a-glmakie-animation/115255>\
**Category:** New to Julia\
**Tags:** glmakie, observables\
**Created:** [June 5, 2024, 7:35pm UTC](https://discourse.julialang.org/t/how-to-use-observable-to-update-multiple-updates-to-a-glmakie-animation/115255 "2024-06-05T19:35:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thushara\_Gunaratne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thushara_gunaratne/32/20372_2.png) [@Thushara\_Gunaratne](https://discourse.julialang.org/u/Thushara_Gunaratne)\
**Post date:** [June 5, 2024, 7:35pm UTC](https://discourse.julialang.org/t/how-to-use-observable-to-update-multiple-updates-to-a-glmakie-animation/115255/1 "2024-06-05T19:35:20Z")

</div>

I’m trying to generate an animation with multiple observables as in the following code:

```julia
using GLMakie

# Define some sample data (replace with your actual data)
x = range(0.0, 2.0, length=101)
data1 = Observable(sin.(2*x))
data2 = Observable(cos.(3*x))
data3 = Observable(sin.(4*x))

# Define the animation function (replace with your logic)
function update_data(frame)
  # Simulate some data update for animation (adjust as needed)
  data1 = sin.(2*x .+ frame * 0.1)
  data2 = cos.(3*x .- frame * 0.3)
  data3 = sin.(4*x)
  return data1, data2, data3
end

# Create the plot and initial scatter objects
fig = Figure()
ax = Axis(fig[1,1], 
            title = "Stacked Scatter Plots",
            xlabel = "X",
            ylabel = "Y"
            #aspect = DataAspect()
            )

# Initial scatter plots with transparency for stacking effect
scatter1 = scatter!(ax, x, data1, label="Data 1", color=:red, alpha=0.7)
scatter2 = scatter!(ax, x, data2, label="Data 2", color=:blue, alpha=0.7)
scatter3 = scatter!(ax, x, data3, label="Data 3", color=:green, alpha=0.7)

# Animation loop with stacking and update
nframes = 100
record(fig, "misc/stacked_scatter.mp4", 1:nframes; framerate=25) do frame
  # Update data for animation
  data1, data2, data3 = update_data(frame)
end

```

But I the resulting animation only shows the initial state. Please show me where I went wrong?

---

<div class="post-metadata">

**Author:** ![Thushara\_Gunaratne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thushara_gunaratne/32/20372_2.png) [@Thushara\_Gunaratne](https://discourse.julialang.org/u/Thushara_Gunaratne)\
**Post date:** [June 5, 2024, 9:04pm UTC](https://discourse.julialang.org/t/how-to-use-observable-to-update-multiple-updates-to-a-glmakie-animation/115255/2 "2024-06-05T21:04:44Z")

</div>

[quote=“Thushara\_Gunaratne, post:1, topic:115255”]  
I was missing the square brackets ☹

```julia
# Define the animation function (replace with your logic)
function update_data(frame)
  # Simulate some data update for animation (adjust as needed)
  data1[] = sin.(2*x .+ frame * 0.1)
  data2[] = cos.(3*x .- frame * 0.3)
  data3[] = sin.(4*x)
  return data1, data2, data3
end

```
