【发布时间】:2023-03-24 12:35:02
【问题描述】:
我正在寻找一种方法来更新动画中的轮廓线,而无需我每次都重新绘制图形。
我发现对这个问题的大多数回复都提倡回忆ax.contour,但由于我的轮廓叠加在另一张图像上,所以速度慢得无法忍受。
我发现的唯一一个看起来接近回答问题的回答是用死链接回答它:Animating a contour plot in matplotlib using FuncAnimation
编辑:this 可能是预期的链接。
示例代码:
#!/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()
干杯。
【问题讨论】:
标签: python matplotlib