用Maltpoltlib使用轮廓为PCOLORMESH动画



我正在研究某件事:我需要对进度进行进步,让我们在表面上和表面上说热。

我遇到了一些麻烦,用轮廓为PCOLORMESH动画:轮廓确实是动画的,但是PcolorMesh却没有。我只得到一个永不替代的第一个。

我的代码很像这样:

#x, y and z_temp are previously extracted from an Excel file
z=np.zeros(time,y,x)
for t in range(time):
    for m in range(len(y)):
        for n in range(len(x)):
            z[t][m][n] = z_temp[t]
x,y=np.meshgrid(x,y)
im = ax.contour(x, y, z[0], 20)
fond = ax.pcolormesh(x, y, z[0], cmap=cm.get_cmap('afmhot_r'))
def animate(t):
    print(t)
    ax.cla()
    fond = ax.pcolormesh(x, y, z[t], cmap=cm.get_cmap('afmhot_r'))
    im = ax.contour(x, y, z[t], 20, cmap=cm.get_cmap('cool'))
    return im, fond,
ani = anima.FuncAnimation(fig, animate, frames=time, interval=400, repeat_delay=1000)
plt.show()

我试图受到这篇文章的启发:用matplotlib中的pcoLormesh例程动画,如何初始化数据?以及这次处理动画的其他人,但我似乎无法结合我发现的解决方案。遵循链接的解决方案,我根本没有任何东西...

谁能帮忙?

编辑:

也许我应该对自己的其他尝试更具体。我将" Def Animate(t)"部分替换为只有我的轮廓的东西,但仍然是动画的:

def init():
    fond.set_array(np.array([]))
    return im, fond,
def animate(t):
    print(t) 
    ax.cla()  
    fond.set_array(z[t])  
    im = ax.contour(x, y, z[t], 20, cmap=cm.get_cmap('cool'))  
    return im, fond,

超过某些编码错误,我不明白为什么这在功能上不起作用。这个最小的示例无问题地更新pcolormeshcontour的C。您可以测试一下以查看它是否适合您?

import numpy as np
import matplotlib.pylab as plt
import matplotlib.animation as animation
time = 10
x = np.linspace(0,5,6)
y = np.linspace(0,6,7)
z = np.random.random((time, y.size, x.size))
fig  = plt.figure()
ax   = plt.subplot(111)
im   = ax.contour(x, y, z[0], 20)
fond = ax.pcolormesh(x, y, z[0], cmap=plt.cm.get_cmap('afmhot_r'))
def animate(t):
    print(t)
    ax.cla()
    fond = ax.pcolormesh(x, y, z[t], cmap=plt.cm.get_cmap('afmhot_r'))
    im   = ax.contour(x, y, z[t], 20, cmap=plt.cm.get_cmap('cool'))
    return im, fond,
ani = animation.FuncAnimation(fig, animate, frames=time, interval=400, repeat_delay=1000)
plt.show()

最新更新