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()
干杯。