Re: [Matplotlib-users] Matplotlib-users Digest, Vol 66, Issue 11

2011-11-04 Thread Stuart Mumford
Hello,

Thanks for your help.

Do you need the colorbar scale to change with each frame?  If not, you can
 create a wholly independent colorbar like so:


Yes, I do need the colour bar to update with each frame unfortunately!


What I would do is prime the pump by creating the first frame.  Then
 create a func animator that calls a function that loads the cached results
 based on an index number and directly update the imshow()'s object using
 the set_data() method.


I see what you mean here, the problem is that while I could do it I think
it would take more memory because each frame is a composite if a few data
sets, and also I quite like the separation of the data and the animation.

Just a thought, would it be possible to combine the two, to create a list
of artists that stores the AxesImage and Line2D object I have for each
subplot and then create a FuncAnimate to add a colorbar and animate them?

Or (continuing thinking this up) to create a list of axes objects
(subplots) then add colorbars to them and just add them to a figure??



 That way, the original colorbar sees the changes from the ScalarMappable
 object that was originally assigned to it.  It also results in faster
 rendering, in my experience since imshow() has many extra steps to take to
 prepare the data for display.


Not really sure what you mean by faster rendering in this context, surely
the rendering done when you draw the Artist in ArtistAnimate is the same
speed as drawing out of a FuncAnimate?



 Note, this won't work if the domain changes over time.


What the size of the domain or the Vlim's??

Thanks again
Stuart
--
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Animation module

2011-11-03 Thread Stuart Mumford
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
 module
 repeat_delay=1000)
   File /usr/lib64/python2.7/site-packages/matplotlib/animation.py, line
 356, in __init__
 TimedAnimation.__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_draw
 artist.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_timer
 TimerBase._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 _step
 still_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_frame
 self._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_draw
 a.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
--
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users