# Animating 10 steps

**URL:** <https://discourse.julialang.org/t/animating-10-steps/76839>\
**Category:** New to Julia\
**Tags:** plotting\
**Created:** [February 21, 2022, 1:05pm UTC](https://discourse.julialang.org/t/animating-10-steps/76839 "2022-02-21T13:05:33Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mahmoud](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Mahmoud](https://discourse.julialang.org/u/Mahmoud)\
**Post date:** [February 21, 2022, 1:05pm UTC](https://discourse.julialang.org/t/animating-10-steps/76839/1 "2022-02-21T13:05:33Z")

</div>

![fig2](https://global.discourse-cdn.com/julialang/original/3X/7/d/7ddeb3ba6b71e20ed9b20ffcda135dc4eeaffa32.png)  
I have 100 points each point simulates a person at specific position plotted like in the attached image using the scatter! function scatter!((x,y))  
’ ’ ’ for i in 1:100  
#scatter!((x,y))  
end  
’ ’ ’  
I started to move them randomly for 10 steps or 10 times  
for i in 1:10  
for j in number\_of\_points  
#move randomly  
end  
end  
I need to plot the result after each step (one different image for each step )and animate all these images together so i can see how these points move each time.  
the problem for me is that the scatter! function combine the old image with new image in single image so I cannot have a separate image that indicates movement at each step. any help please?

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [February 21, 2022, 1:16pm UTC](https://discourse.julialang.org/t/animating-10-steps/76839/2 "2022-02-21T13:16:19Z")

</div>

```julia
julia> using Plots

julia> @gif for i in 1:10
           scatter(rand(10),rand(10))
       end
┌ Info: Saved animation to 
└ fn = "/tmp/jl_DAZY9K.gif"
Plots.AnimatedGif("/tmp/jl_DAZY9K.gif")

```

That produces an animation (of course you can tune all details of those plots). But maybe your question isn’t clear.

Please read: [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757)

---

<div class="post-metadata">

**Author:** ![Mahmoud](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Mahmoud](https://discourse.julialang.org/u/Mahmoud)\
**Post date:** [February 21, 2022, 2:13pm UTC](https://discourse.julialang.org/t/animating-10-steps/76839/3 "2022-02-21T14:13:30Z")

</div>

thanks for your reply, I have updated my question.  
I am using the function (scatter!) not (scatter) to keep points together on a single image as I draw point by point. so this generates image one. then , I moved them randomly for 10 times this should gives image 2,3,4,5,6,7,8,9,10 so i can animate them together.  
the problem is that each image has the data of previous image. for example, Image 3 = image 1(position) + image (2) position + new position

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [February 21, 2022, 2:20pm UTC](https://discourse.julialang.org/t/animating-10-steps/76839/4 "2022-02-21T14:20:37Z")

</div>

Use `scatter` without the `!`. And please, follow the guidelines of that post in your questions, otherwise it is hard to really help.

---

<div class="post-metadata">

**Author:** ![Mahmoud](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Mahmoud](https://discourse.julialang.org/u/Mahmoud)\
**Post date:** [February 21, 2022, 2:26pm UTC](https://discourse.julialang.org/t/animating-10-steps/76839/5 "2022-02-21T14:26:55Z")

</div>

the main code is too long I just try to simplify my problem.  
 ![plot_6](https://global.discourse-cdn.com/julialang/original/3X/6/c/6cc1e35e2297235c2c3e4c2b2722fd1f68f09652.gif)  
using scatter without ! will not plot the points together.  
this gif shows that points are expanding instead of just moving random and this is because the old data is kept in the new image.(my problem is only in representing the data)

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [February 21, 2022, 2:31pm UTC](https://discourse.julialang.org/t/animating-10-steps/76839/6 "2022-02-21T14:31:20Z")

</div>

You don’t need to plot _one point at a time_. You can use, for example:

```julia
julia> x = [rand(2) for _ in 1:100];

julia> scatter(Tuple.(x))

```

and that will plot all points in array `x` at once.

---

<div class="post-metadata">

**Author:** ![Mahmoud](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Mahmoud](https://discourse.julialang.org/u/Mahmoud)\
**Post date:** [February 21, 2022, 2:49pm UTC](https://discourse.julialang.org/t/animating-10-steps/76839/7 "2022-02-21T14:49:13Z")

</div>

I think I am near this is my array  
’ ’ ’ Person = [Dict(“x” =\> 0,“y” =\> 0,“color” =\> “white”) for i ∈ 1:100]  
#some code to change the x and y value to each person ’ ’ ’  
how to plot it at once ?

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [February 21, 2022, 3:37pm UTC](https://discourse.julialang.org/t/animating-10-steps/76839/8 "2022-02-21T15:37:16Z")

</div>

`scatter([Person[i]["x" for i in 1:100], [Person[i]["y"] for i in 1:100])`

---

<div class="post-metadata">

**Author:** ![Mahmoud](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Mahmoud](https://discourse.julialang.org/u/Mahmoud)\
**Post date:** [February 21, 2022, 3:50pm UTC](https://discourse.julialang.org/t/animating-10-steps/76839/9 "2022-02-21T15:50:01Z")

</div>

Could you just add the color to the same plot as each person has different color?

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [February 21, 2022, 3:54pm UTC](https://discourse.julialang.org/t/animating-10-steps/76839/10 "2022-02-21T15:54:46Z")

</div>

Yes, you can. See `marker_z` here [Series Attributes · Plots](https://docs.juliaplots.org/stable/generated/attributes_series/)

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [February 21, 2022, 6:29pm UTC](https://discourse.julialang.org/t/animating-10-steps/76839/12 "2022-02-21T18:29:59Z")

</div>

An alternative to @Jeff_Emanuel’s comprehension:

```julia
scatter(getindex.(Person,"x"), getindex.(Person,"y"))

```
