我正在尝试使用Matplotlib的圆形和动画来模拟从选定数据点发出的圆形冲击波的动画。但是我无法找到一种方法在每个新帧中删除旧的圆。因此,随着半径的增加,我得到了越来越多的圆在画布上绘制 - 就像这样:
有关在matplotlib图中制作循环冲击波的任何建议?
我目前拥有的代码是:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
testData = np.random.rand(100,2)-[0.5, 0.5]
fig, ax = plt.subplots()
def init():
fig.clf()
sctPlot, = ax.plot(testData[:,0], testData[:,1], ".")
# i is the radius
def animate(i):
init()
q = 20 #initial index for the starting position
pos = testData[q,:]
circle1=plt.Circle(pos,i,color='r',fill=False, clip_on = False)
fig.gca().add_artist(circle1)
def init():
sctPlot, = ax.plot(testData[:,0], testData[:,1], ".")
return sctPlot,
ani = animation.FuncAnimation(fig, animate, np.arange(0.4, 2, 0.1), init_func=init,
interval=25, blit=False)
plt.show()
%matplotlib
进行了检查,并且确实返回了“使用matplotlib后端:MacOSX”。 - CT Zhu