我想模拟使用Matplotlib的圆和动画从选定的数据点的圆形激波的动画。 但我无法想出一种方法来删除每个新框架中的旧圈子。其结果是,随着半径增大,我得到了越来越多的圈在画布上绘制 - 这样的: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()
谢谢... set_radius正是我所需要的。非常感激。 –
嗨,再次。新代码工作正常,但不在ipython笔记本上。它似乎崩溃了内核。我用%pylab tk弹出了plt窗口。你认为这与此有关吗? –
可能是传统知识问题?如果你不在ipython笔记本上,它有效吗?我使用OSX后端,根本没有得到这个问题。 –