Repository navigation
'QuadContourSet' object has no attribute 'set_visible' or 'set_animated' #6139
Copy link
Copy link
Closed
Labels
API: consistencyConsistency of the matplotlib API, including naming, behavior, defaults, …Consistency of the matplotlib API, including naming, behavior, defaults, …
Milestone
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()
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
API: consistencyConsistency of the matplotlib API, including naming, behavior, defaults, …Consistency of the matplotlib API, including naming, behavior, defaults, …
Activity
tacaswell commentedon Mar 10, 2016
Because (surprisingly)
ContourSetsare notArtists. The actual artists are in thecollectionattribute as you discovered.I am 👎 on including this type of fix upstream, this should probably be fixed by promoting
ContourSetsto beingArtists(which means they get all the expected methods, end up in the draw tree etc) which is a pretty major refactor job.A simpler fix for your case would be
WeatherGod commentedon Mar 10, 2016
Could you check to see if just simply passing "corner_mask='legacy'" to the
contourf() call works. This might be a regression.
On Thu, Mar 10, 2016 at 8:37 AM, Thomas A Caswell notifications@github.com
wrote:
fabrivelas commentedon Mar 10, 2016
@WeatherGod "corner_mask='legacy' did not work. It also gave me a warning to use corner_mask=False or True instead.
@tacaswell thanks for your improvement. The imshow method does not seem to work, however, if I want to use Basemap (hence the lat and lon variables ;-) ). I guess I then just use m.contourf instead of ax.contourf:
WeatherGod commentedon Mar 10, 2016
@fabrivelas, yeah, the warning message is because the "legacy" mode is
deprecated, but it forces the use of the old codepaths. I am not sure how
this used to work in 1.3.1 if the legacy flag doesn't work either.
On Thu, Mar 10, 2016 at 10:01 AM, fabrivelas notifications@github.com
wrote:
tacaswell commentedon Mar 10, 2016
@WeatherGod The change is that with the auto-draw changes animation became much stricter about making sure it's artists were actually in 'animated' mode. In 1.3.1 the OP only had to monkey-patch
set_visible, in 1.5 + monkey patchingset_animatedis also needed.In either case, it was abuse of the
ArtistAnimationAPI in that non-artists were in the list and an inconsistency in thatcontourfdoes not retrun anArtist.Tried to add animation support for a contour map but it turns out thi…
ellieLitwack commentedon Jun 28, 2022
Just want to add that this issue breaks using interactive functions to place clabels as shown in this matplotlib.org tutorial: https://matplotlib.org/stable/gallery/event_handling/ginput_manual_clabel_sgskip.html
github-actions commentedon Jun 30, 2023
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
QuLogic commentedon Jun 30, 2023
This was fixed by #25247 turning
ContourSetintoCollection.fabrivelas commentedon Jun 30, 2023
For reference the code from the original message from 2016 above has been working when using the workaround by adding the artists suggested by @tacaswell
add_arts = im.collectionsbut not otherwise, which is probably intended. :-)