I was trying to make an animation using pcolormesh but my code was having problems, so I decided to use one of the answers in this post as a starting point. The answer had too many plots in it and I only needed the pcolormesh, so I removed the unnecessary plots. The puzzling thing is that removing the plots broke the animation for some reason. I made some minimal example that contains the pcolormesh and some text. The code works as long as I don't comment the text update but I'm unable to figure why.
My questions are the following: Is there any reason the pcolormesh won't update in some scenarios? How can I fix the animation without adding other plots or text?
Note: I'm using OSX which apparenlty has some issues with the blit option.
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
y, x = np.meshgrid(np.linspace(-10, 10,100), np.linspace(-10, 10,100))
z = np.sin(x)*np.sin(x)+np.sin(y)*np.sin(y)
fig = plt.figure(figsize=(16, 8),facecolor='white')
ax = plt.subplot()
quad = ax.pcolormesh(x,y,z,shading='gouraud')
ax.set_xlabel('time')
ax.set_ylabel('amplitude')
cb = fig.colorbar(quad,ax=ax)
time_text = ax.text(0.02, 0.95, 'start', transform=ax.transAxes)
def animate(iter):
z = np.sin(x-iter/(2*np.pi))*np.sin(x-iter/(2*np.pi))+np.sin(y)*np.sin(y)
time_text.set_text(str(iter)) #comment this line to break the animation
quad.set_array(z.ravel())
anim = animation.FuncAnimation(fig,animate,frames=100,interval=50,blit=False,repeat=False)
plt.show()
Edit: As it was pointed out in the comments, it had to do with the backend. My updated questions are: why does this code fail for some backends? Shouldn't the behavior of pcolormesh be independent of the text added?