我想模擬使用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後端,根本沒有得到這個問題。 –