Closed
Description
matplotlib/1.5.1
python3/3.5.1
osx 10.11.3
Installation using homebrew.
The following code gives me an error 'QuadContourSet' object has no attribute 'set_visible'
I added a workaround (http://stackoverflow.com/questions/23070305/how-can-i-make-an-animation-with-contourf) and it worked for version 1.3.1 of matplotlib but with matplotlib version 1.5.1 I get the error 'QuadContourSet' object has no attribute 'set_animated'. Adding extra code similar to that for 'set_visible' makes the code work again.
I would expect the code to work without the Bug fix code snippets included.
#! coding=utf-8
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
import types
#################################################################
## Bug fix for Quad Contour set not having attribute 'set_visible'
def setvisible(self,vis):
for c in self.collections: c.set_visible(vis)
def setanimated(self,ani):
for c in self.collections: c.set_animated(ani)
####################################################################
fig = plt.figure()
# Some 2D geo arrays to plot (time,lat,lon)
data = np.random.random_sample((20,90,360))
lat = range(len(data[0,:,0]))
lon = range(len(data[0,0,:]))
lons,lats = np.meshgrid(lon,lat)
# ims is a list of lists, each row is a list of artists to draw in the
# current frame; here we are animating three artists, the image and 2
# annotatons (title), in each frame
ims = []
for i in range(len(data[:,0,0])):
t_step = int(i)
im = plt.contourf(lons,lats,data[i,:,:])
text = 'title=' + str(i)
te = plt.text(90,90,str(text))
an = plt.annotate(str(text), xy=(0.45, 1.05), xycoords='axes fraction')
#################################################################
## Bug fix for Quad Contour set not having the attributes
## 'set_visible' and 'set_animated'
# ** uncomment the following 2 lines to make the code work:**
# im.set_visible = types.MethodType(setvisible,im)
# im.set_animated = types.MethodType(setanimated,im)
im.axes = plt.gca()
im.figure = fig
####################################################################
ims.append([im,te,an])
#ani = animation.ArtistAnimation(fig, ims, interval=70,repeat_delay=1000, blit=False)
ani = animation.ArtistAnimation(fig, ims)
## For saving the animation we need ffmpeg binary:
#FFwriter = animation.FFMpegWriter()
#ani.save('basic_animation.mp4', writer = FFwriter)
plt.show()