I am just starting a small particle simulator I wish to expand to solve some physics problems but I have a problem trying to animate them. Essentially depending on what kind of random distribution you choose the particles will "oscillate" in an area of a given length. I want to show the "history" of the particle at say the 10 previous steps.
Here is the code
from numpy import *
import matplotlib.pyplot as plt
import pylab
import time
pylab.ion()
N = 10
r = random.randint(-100,100,2*N).reshape(N,2)
line, = plt.plot(r[:,0], r[:,1],'o')
for i in range(100000):
newdatax = r[:,0] + random.rand(N)
newdatay = r[:,1] + random.rand(N)
line.set_ydata(newdatay)
line.set_xdata(newdatax)
plt.title("At timestep: %d" %i)
plt.hold(True)
plt.draw()
time.sleep(1.0/30)
What I want is for the line update to NOT clear the canvas and redraw at every iteration, I just want it to do that for say, every 10th frame (iteration), this will make it easier for me to track the particles visually.
There is another thing I wish to implement but it is not strictly necessary, is it possible to draw a box (square) or a circle or a triangle around each "o"? Such that the point is centered in that box/circle/triangle? This would again make it much easier to track particles. It would be even nicer if I could dictate which "o" (point) gets this property (square).