# Problem with an observable array of varying length in Makie.jl

**URL:** https://discourse.julialang.org/t/problem-with-an-observable-array-of-varying-length-in-makie-jl/22638
**Category:** Visualization
**Tags:** error
**Created:** [April 2, 2019, 1:50pm UTC](https://discourse.julialang.org/t/problem-with-an-observable-array-of-varying-length-in-makie-jl/22638 "2019-04-02T13:50:56Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![skarp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skarp/32/33928_2.png) [@skarp](https://discourse.julialang.org/u/skarp)
#### Post date: [April 2, 2019, 1:50pm UTC](https://discourse.julialang.org/t/problem-with-an-observable-array-of-varying-length-in-makie-jl/22638/1 "2019-04-02T13:50:56Z")

</div>

Hello.

I am facing a problem with Observables (of varying length) in Makie.jl. The problem can be summarised to the following minimal example:

```julia
using Makie
#AbstractPlotting.inline!(true) # Uncomment if using Atom and Juno.

# Made up data.
x = rand(10);
y = rand(10);

# Make x_i and y_i depend on the value of the observable i.
i = Node(1); # Initialise observable i to the value of 1.
x_i = lift(t -> x[1:t], i); # The length of x_i and y_i is determined by the value of i.
y_i = lift(t -> y[1:t], i);

scene = Scene(limits = FRect(0.0, 0.0, 2.0, 2.0));
scatter!(scene, x_i, y_i); # A scatter plot with x_i on the x axis and y_i on the y axis.
scene # See a plot with one point, as the observable i has value 1, everything is fine.
push!(i, 2); # Change value of the observable i to 2.
scene # See a plot with two points, everything is fine.
push!(i, 3); # DimensionMismatch("arrays could not be broadcast to common size") ???

```

Why do I get the error on the last line? To me this does not make any sense, as changing the value of `i` to 2 works. I noticed, that if I instead write:

```julia
x_i = lift(t -> x[1:t], i);
y_i = lift(t -> y[1:length(t)], x_i);

```

the error disappears. Hopefully someone can explain what is going on? I was under the impression that multiple values can depend on the same Observable.

My use case is making an animation that plots my data up to time index i.

---

<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: [April 2, 2019, 2:08pm UTC](https://discourse.julialang.org/t/problem-with-an-observable-array-of-varying-length-in-makie-jl/22638/2 "2019-04-02T14:08:43Z")

</div>

I’d just use an array of points, e.g. with Point2f0.(x, y)

---

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [April 2, 2019, 2:58pm UTC](https://discourse.julialang.org/t/problem-with-an-observable-array-of-varying-length-in-makie-jl/22638/3 "2019-04-02T14:58:37Z")

</div>

I am interested in a similar case, with varying number of `arrows` instead of `scatter`. Is that also possible?

```julia
using Makie
# Made up data.
N = 100
pos = [rand(Point3f0) for _ in 1:N]
vel = [rand(Point3f0) for _ in 1:N]

# Make x_i and y_i depend on the value of the observable i.
i = Node(10); # Initialise observable i to the value of 1.
pos_i = lift(t -> pos[1:t], i); # The length of x_i and y_i is determined by the value of i.
vel_i = lift(t -> vel[1:t], i);

scene = Scene(limits = FRect(0.0, 0.0, 2.0, 2.0));
scene = Scene()
arrows!(scene, pos_i, vel_i)
display(scene)
push!(i, 20)

```

---

<div class="post-metadata">

### Author: ![skarp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skarp/32/33928_2.png) [@skarp](https://discourse.julialang.org/u/skarp)
#### Post date: [April 2, 2019, 4:08pm UTC](https://discourse.julialang.org/t/problem-with-an-observable-array-of-varying-length-in-makie-jl/22638/4 "2019-04-02T16:08:11Z")

</div>

Thank you for your answer, but can you explain why exactly this happens?
