Animating 10 steps

fig2
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?

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

2 Likes

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

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

the main code is too long I just try to simplify my problem.
plot_6
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)

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

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

julia> scatter(Tuple.(x))

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

1 Like

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 ?

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

1 Like

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

Yes, you can. See marker_z here Series Attributes · Plots

1 Like

An alternative to @Jeff_Emanuel’s comprehension:

scatter(getindex.(Person,"x"), getindex.(Person,"y"))
2 Likes