# Issues with animation by plotting via for-loops

**URL:** <https://discourse.julialang.org/t/issues-with-animation-by-plotting-via-for-loops/34940>\
**Category:** New to Julia\
**Tags:** question, plotting\
**Created:** [February 20, 2020, 10:49pm UTC](https://discourse.julialang.org/t/issues-with-animation-by-plotting-via-for-loops/34940 "2020-02-20T22:49:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![badmin](https://avatars.discourse-cdn.com/v4/letter/b/c67d28/32.png) [@badmin](https://discourse.julialang.org/u/badmin)\
**Post date:** [February 20, 2020, 10:49pm UTC](https://discourse.julialang.org/t/issues-with-animation-by-plotting-via-for-loops/34940/1 "2020-02-20T22:49:36Z")

</div>

Hi,

I have x,y,z coordinates over time for a few points on a moving object, that i want to animate using Julia. In the end, i would like to have an interactive animation that can be rotated while the animation is running, but im trying to take baby steps here. So a gif/video of the actual movement, maybe with a rotating camera is my current goal.

The input is a CSV file which i read and convert:

```julia
movement = convert(Matrix,CSV.read("data.csv"))

```

The array movement becomes a 1118x37 Array{Float64,2} after this operation, and i can successfully plot the path of one of the points using:

```julia
scatter3d(movement[:,1],movement[:,2],movement[:,3])

```

Now to the problem, when i try to animate following the two examples on [Animations · Plots](https://docs.juliaplots.org/latest/animations/), i get the following:

**Example 1**

```julia
anim = @animate for i=1:100
    scatter3d(movement[i,2],movement[i,4],movement[i,3])
end
gif(anim, "out.gif", fps=15)

```

**Example 2**

```julia
@gif for i=1:100
    scatter3d(movement[i,2],movement[i,4],movement[i,3])
end every 10

```

Here i gave up and tried to just plot a single value plot(movement[1,2],movement[1,4],movement[1,3])

Output in all cases:

```julia
"ERROR: Cannot convert Float64 to series data for plotting"

```

I am using Plots with the plotly backend.  
What am i missing? Why cant i even just plot a simple point in 3D using scatter? If i input some random decimal numbers manually it works just fine, but for some reason when i specify them from the array, it does not work.

Thanks in advance for any advice!

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [February 20, 2020, 11:17pm UTC](https://discourse.julialang.org/t/issues-with-animation-by-plotting-via-for-loops/34940/2 "2020-02-20T23:17:23Z")

</div>

> [@Animations with PlotlyJS?](https://discourse.julialang.org/t/animations-with-plotlyjs/34633/2):
>
> FYI: PlotlyJS.jl turns out to be quite capable with respect to animated graphics, displayed from a running program. Kudos to @sglyon! [[s]](https://www.dropbox.com/s/jt3jcr4q3zo7zky/argyris-vib-anim.gif?dl=0) addtraces! and deletetraces! did not work. Perhaps I was doing it wrong. But react! was just the ticket. Code at [GitHub - PetrKryslUCSD/FinEtoolsFlexBeams.jl: Finite Element tools in Julia: large-displacement response of 3D flexible frame structures](https://github.com/PetrKryslUCSD/FinEtoolsFlexBeams.jl)

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [February 20, 2020, 11:26pm UTC](https://discourse.julialang.org/t/issues-with-animation-by-plotting-via-for-loops/34940/3 "2020-02-20T23:26:30Z")

</div>

You are trying to plot scalars (e.g. `(movement[i,2])`) but `plot` expects Vectors. The distinction between scalars and vectors might be surprising if you’re used to R or matlab (where scalars don’t exist and everything is a vector/matrix).  
To plot a single point, use a length 1 vector, e.g. by indexing with a range: `scatter3d(movement[i:i,2],movement[i:i,4],movement[i:i,3])`
