I am working on something : I need to vizualize the progress of, let us say heat, in time and on a surface.
I\'m having some troubles animating a pcolormesh with contour
Beyond some coding errors, I don't see why this functionally wouldn't work. This minimal example updates both the pcolormesh
and contour
's without a problem. Could you test this to see if it works for you?
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()