Hello,
I discovered the (wonderful) animation module in the v1.1 release today.
However I think I may have quickly outgrown it a bit!
I am plotting some simulation data see: http://dl.dropbox.com/u/2796140/mhdmodes_3.mp4 for an example made with the animation class.
There is one thing missing from the above, which is colour bars!
I have created the animation using the ArtisitAnimation class because each frame takes about 1-2 seconds to calculate the magnetic field lines, so using FuncAnimate would result in a very slow animation.
The problem is that I can not add a colorbar instance to the list of artists that the animator draws as it is not an artist instance.
This is a slightly modified version of the example [http://matplotlib.sourceforge.net/examples/animation/dynamic_image2.html] that shows my problem:
#!/usr/bin/env python
“”"
An animated image
“”"
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
def f(x, y):
return np.sin(x) + np.cos(y)
x = np.linspace(0, 2 * np.pi, 120)
y = np.linspace(0, 2 * np.pi, 100).reshape(-1, 1)
ims is a list of lists, each row is a list of artists to draw in the
current frame; here we are just animating one artist, the image, in
each frame
ims =
for i in range(60):
x += np.pi / 15.
y += np.pi / 20.
im = plt.imshow(f(x, y))
cb = plt.colorbar()
ims.append([im, cb])
ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True,
repeat_delay=1000)
plt.show()
Which generates the following error
Traceback (most recent call last):
File “/home/stuart/Documents/VAC/sac_anim_axtest.py”, line 28, in
repeat_delay=1000)
File “/usr/lib64/python2.7/site-packages/matplotlib/animation.py”, line 356, in initTimedAnimation.__init__(self, fig, *args, **kwargs)
File “/usr/lib64/python2.7/site-packages/matplotlib/animation.py”, line 304, in init
Animation.init(self, fig, event_source=event_source, *args, **kwargs)File “/usr/lib64/python2.7/site-packages/matplotlib/animation.py”, line 53, in init
self._init_draw()
File “/usr/lib64/python2.7/site-packages/matplotlib/animation.py”, line 363, in _init_drawartist.set_visible(False)
AttributeError: Colorbar instance has no attribute ‘set_visible’
I attempted to add the colorbar to a AxesSubplot instance and then draw the axes in the artist list, however when I add a Axes instance to the artist list I get a wonderful error:
Traceback (most recent call last):
File “/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtk.py”, line 122, in _on_timerTimerBase._on_timer(self)
File “/usr/lib64/python2.7/site-packages/matplotlib/backend_bases.py”, line 1092, in _on_timer
ret = func(*args, **kwargs)
File “/usr/lib64/python2.7/site-packages/matplotlib/animation.py”, line 315, in _stepstill_going = Animation._step(self, *args)
File “/usr/lib64/python2.7/site-packages/matplotlib/animation.py”, line 177, in _step
self._draw_next_frame(framedata, self._blit)
File “/usr/lib64/python2.7/site-packages/matplotlib/animation.py”, line 197, in _draw_next_frameself._post_draw(framedata, blit)
File “/usr/lib64/python2.7/site-packages/matplotlib/animation.py”, line 220, in _post_draw
self._blit_draw(self._drawn_artists, self._blit_cache)
File “/usr/lib64/python2.7/site-packages/matplotlib/animation.py”, line 235, in _blit_drawa.axes.draw_artist(a)
File “/usr/lib64/python2.7/site-packages/matplotlib/axes.py”, line 1994, in draw_artist
assert self._cachedRenderer is not None
AssertionError
I also saw the subplots animation example [http://matplotlib.sourceforge.net/examples/animation/subplots.html], however that is also based on FuncAnimate, would there be a way to create something similar for ArtistAnimate?
Thanks
Stuart