4
我正在尋找一種方法來更新我的輪廓線,動畫不需要我每次重新繪製圖形。更新matplotlib動畫的輪廓
對這個問題的最多回復我發現主張回憶ax.contour
,但因爲我的輪廓疊加在另一張圖片上,這是難以忍受的緩慢。
我發現,接近前回答這個問題有死鏈接答案是唯一的迴應:Animating a contour plot in matplotlib using FuncAnimation
示例代碼:
#!/usr/bin/env python
import matplotlib.pylab as plt
import matplotlib.animation as anim
from matplotlib.colors import LinearSegmentedColormap as lsc
import numpy
#fig = 0; ax = 0; im = 0; co = 0
image_data = numpy.random.random((100,50,50))
contour_data = numpy.random.random((100,50,50))
def init():
global fig, ax, im, co
fig = plt.figure()
ax = plt.axes()
im = ax.imshow(image_data[0,:,:])
co = ax.contour(contour_data[0,:,:])
def func(n):
im.set_data(image_data[n,:,:])
co.set_array(contour_data[n,:,:])
init()
ani = anim.FuncAnimation(fig, func, frames=100)
plt.show()
乾杯。