Reputation: 455
I have written a simple python code for animation. The code creates random points and then plots them during the animation.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
x = 10*np.random.rand(10,1)
y = 10*np.random.rand(10,1)
fig = plt.figure()
ax = plt.axes(aspect='equal',xlim =(-10,10), ylim = (-10,10))
plts = ax.plot([], [], 'o-')
def init():
plts.set_data([],[])
return plts
def animate(num,x,y,plots,skip):
plts[0].set_data(x[:num*skip],y[:num*skip])
return plts
skip = 1
ani = animation.FuncAnimation(fig,
animate,
frames=10,
fargs =(x,y,plts,skip),
interval=1000)
plt.show()
During the animation, the code plots all the points.
Can someone tell me how to plot only one point in a frame and clear the previous point ?
Upvotes: 0
Views: 682
Reputation: 339600
At the moment you plot all the points in the list, up to index num*skip
. Each frame num
is increased by 1 and therefore one additional point is plotted.
In order to plot only the num
th point, simply use
plts[0].set_data(x[num],y[num])
Upvotes: 1