dynamic colorbar

One of my favorite aspects of matplotlib is how easy it

    > is to make dynamic plots. When doing this with 2D
    > renderings using pcolor or imshow, is there an easy way
    > to also dynamically update the colorbar?

It should *just work*. images (matplotlib.image.AxesImage) and
pcolors (matplotlib.collections.PolygonCollection) both derive from
matplotlib.cm.ScalarMappable. This class implements an observer
pattern, and the colorbar registers itself with the ScalarMappable
instance. If you change the normalization, or colormap, or
colorlimits, the ScalarMappable instance notifies it's observers, who
update automagically.

Let me know if you run into any troubles.

JDH

Ok, here's the problem, illlustrated by a simple variant of the dynamic_image_gtkagg.py example (see below).
I've put in a colorbar and I'm letting the amplitude of the pattern grow linearly in time. The result is that the colormap limits remained fixed at their initial values (-2,2), rather than change in time. If I don't put in the colorbar, the colormap limits *do* change. I'm a bit confused about all this.
I tried changing the normalization of the colormap doing im.autoscale(z) each time z is updated, but that doesn't work ...

Rodrigo

···

-----------

#!/usr/bin/env python
"""
An animated image
"""
import sys, time, os, gc
from matplotlib import rcParams

from matplotlib.matlab import *
import gtk

x = arange(120.0)*2*pi/120.0
x = resize(x, (100,120))
y = arange(100.0)*2*pi/100.0
y = resize(y, (120,100))
y = transpose(y)
z = sin(x) + cos(y)
im = imshow( z, cmap=cm.jet)#, interpolation='nearest')

colorbar()

manager = get_current_fig_manager()

cnt = 0
tstart = time.time()
def updatefig(*args):
     global x, y, cnt, start
     x += pi/15
     y += pi/20
     z = ( sin(x) + cos(y) ) * cnt/5.
     im.set_array(z)
     manager.canvas.draw()
     cnt += 1
     if cnt==50:
         print 'FPS', cnt/(time.time() - tstart)
         return gtk.FALSE
     return True

cnt = 0

gtk.idle_add(updatefig)
show()

-----------------------------

On Monday, September 13, 2004, at 03:47 PM, John Hunter wrote:

    > One of my favorite aspects of matplotlib is how easy it
    > is to make dynamic plots. When doing this with 2D
    > renderings using pcolor or imshow, is there an easy way
    > to also dynamically update the colorbar?

It should *just work*. images (matplotlib.image.AxesImage) and
pcolors (matplotlib.collections.PolygonCollection) both derive from
matplotlib.cm.ScalarMappable. This class implements an observer
pattern, and the colorbar registers itself with the ScalarMappable
instance. If you change the normalization, or colormap, or
colorlimits, the ScalarMappable instance notifies it's observers, who
update automagically.

Let me know if you run into any troubles.

JDH

-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 13. Go here: http://sf.net/ppc_contest.php
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users