From: John L. <joh...@sb...> - 2011-11-13 21:44:14
|
On Sun, 2011-11-13 at 13:26 -0500, Daniel Hyams wrote: > Oops; my sentence should have read "is *not* derived from an artist". Yes, I was wondering about that. I was actually looking though the artist.py and contour.py source code when your message came in. On Sunday, November 13, 2011, Daniel Hyams <dh...@gm...> wrote: > The following monkey patch fixes it in the example script (obviously, > it does not fix the underlying problem; for QuadContourSet to be > usable in this context, it needs to obey the artist interface). > Hopefully, it will be enough to get you up and running. Just add the > four lines between contour call and the appending of the output of > contour() into the list "ims", and also put an "import types" at the > top. OK, types is a new part of the Python library for me, I'll have to go learn about it. It looks like you basically just subclassed the QuadContourSet object through a back door, by giving it the missing method. Your patch solves one of two animation problems, and I offer a suggestion about how to fix the second (with questions). The program gets as far as ani.save() on line 29 without generating any errors. An MP4 file showing animated contours is written to disk. The origin of the contour plot is in the lower left, versus the upper left of the original imshow() call, but that's expected. When you get to plt.show() on line 31, however: Traceback (most recent call last): File "/usr/local/lib/python2.6/dist-packages/matplotlib/backends/backend_gtk.py", line 127, in _on_timer TimerBase._on_timer(self) File "/usr/local/lib/python2.6/dist-packages/matplotlib/backend_bases.py", line 1091, in _on_timer ret = func(*args, **kwargs) File "/usr/local/lib/python2.6/dist-packages/matplotlib/animation.py", line 317, in _step still_going = Animation._step(self, *args) File "/usr/local/lib/python2.6/dist-packages/matplotlib/animation.py", line 179, in _step self._draw_next_frame(framedata, self._blit) File "/usr/local/lib/python2.6/dist-packages/matplotlib/animation.py", line 199, in _draw_next_frame self._post_draw(framedata, blit) File "/usr/local/lib/python2.6/dist-packages/matplotlib/animation.py", line 222, in _post_draw self._blit_draw(self._drawn_artists, self._blit_cache) File "/usr/local/lib/python2.6/dist-packages/matplotlib/animation.py", line 236, in _blit_draw bg_cache[a.axes] = a.figure.canvas.copy_from_bbox(a.axes.bbox) AttributeError: QuadContourSet instance has no attribute 'figure' Since the error was occurring inside blit_draw, I tried altering the animation.ArtistAnimation() call on line 27, letting blit default to False. This resulted in a successful on-screen rendering, as well as a saved file on the disk. Mission accomplished! Though perhaps at the sacrifice of some speed. Is this error occurring because there is no bit-mapped representation of a contour object? If so, what should matplotlib do? Make the user be aware that blit cannot be used with contour objects, as I just learned? Or, alternately, make sure that animations respond intelligently to the objects passed to them? Many thanks again to everyone who is working through this with me! |