I'm new to matplotlib and trying to animate a 2D colormap to show diffusion in two dimensions. This is a method inside a class called Lattice2D with fields including lat_series (a numpy array of 2D numpy arrays representing the lattice state at each timestep) and shape (the shape of the lattice). Here is my code:
def plotAnimation(self):
"""Animates the lattice as it evolves in time"""
fig, ax = plt.subplots()
X, Y = np.meshgrid(range(self.shape[0]), range(self.shape[1]))
cax = ax.pcolormesh(self.lat_series[0], cmap="RdBu")
def animate(i):
if (i < self.lat_series.shape[0]):
cax = ax.pcolormesh(self.lat_series[i], cmap="RdBu")
return cax
anim = FuncAnimation(fig, animate, interval=20, blit=True, save_count=50)
plt.show()
It keeps throwing this error:
RuntimeError: The animation function must return a sequence of Artist objects.
I'm not sure what an Artist object is, and why cax
isn't one.
Any help would be greatly appreciated!