我正在寻找一种在动画中更新轮廓线的方法,而不需要每次重新绘制图形。
大多数对于这个问题的回答都建议重新调用
我发现的唯一看起来接近回答这个问题的回答是一个死链接:Animating a contour plot in matplotlib using FuncAnimation 编辑:这个可能是预期的链接。
示例代码:
干杯。
大多数对于这个问题的回答都建议重新调用
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()
干杯。