From: Rodrigo C. <rc...@ge...> - 2004-09-13 20:44:14
|
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? Thanks, Rodrigo |
From: John H. <jdh...@ac...> - 2004-09-13 21:37:10
|
>>>>> "Rodrigo" == Rodrigo Caballero <rc...@ge...> writes: Rodrigo> One of my favorite aspects of matplotlib is how easy it Rodrigo> is to make dynamic plots. When doing this with 2D Rodrigo> renderings using pcolor or imshow, is there an easy way Rodrigo> 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 |
From: Rodrigo C. <rc...@ge...> - 2004-09-13 22:37:03
|
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: >>>>>> "Rodrigo" == Rodrigo Caballero <rc...@ge...> writes: > > Rodrigo> One of my favorite aspects of matplotlib is how easy it > Rodrigo> is to make dynamic plots. When doing this with 2D > Rodrigo> renderings using pcolor or imshow, is there an easy way > Rodrigo> 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 > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users |
From: John H. <jdh...@ac...> - 2004-09-14 20:02:53
|
>>>>> "Rodrigo" == Rodrigo Caballero <rc...@ge...> writes: Rodrigo> Ok, here's the problem, illlustrated by a simple variant Rodrigo> of the dynamic_image_gtkagg.py example (see below). I've Rodrigo> put in a colorbar and I'm letting the amplitude of the Rodrigo> pattern grow linearly in time. The result is that the Rodrigo> colormap limits remained fixed at their initial values Rodrigo> (-2,2), rather than change in time. If I don't put in the Rodrigo> colorbar, the colormap limits *do* change. I'm a bit Rodrigo> confused about all this. I tried changing the Rodrigo> normalization of the colormap doing im.autoscale(z) each Rodrigo> time z is updated, but that doesn't work ... OK, I understand the problem now. The reason setting the colorbar caused the behavior you find unusual (the colormap limits remain fixed) stems from the call to if norm.vmin is None or norm.vmax is None: mappable.autoscale() in matplotlib.matlab.colorbar. When the normalization limits are None, the normalization class automatically uses the full range. This call to autoscale sets the normalization limits, and after that they are fixed. I'll have to make some changes to the code to do this right, perhaps creating a colorbar class instance on which you can call various methods to get the desired behavior. The question is: what is the right default behavior, and what are the other kinds of behaviors that should be possible? I imagine that in some cases when you set the array data for the main window, you want to colorbar and color limits to update and autoscale it's range, and in other cases you want the colorbar and limits to autoscale. JDH |
From: Chris <rea...@po...> - 2004-09-13 22:04:07
|
Hi, I have looked had a look around but I have been unable to find out how to change the size (and orientation) of graphs when I save them as eps or png files - using savefig - any help or directions to help would be greatly appreciated. What I want to do is save a graph that is a full page size in landscape orientation. Chris |
From: John H. <jdh...@ac...> - 2004-09-13 22:37:31
|
Chris> Hi, I have looked had a look around but I have been unable Chris> to find out how to change the size (and orientation) of Chris> graphs when I save them as eps or png files - using savefig Chris> - any help or directions to help would be greatly Chris> appreciated. The flags you are looking for a re the figsize argument to the figure command, and the orientation flag to the savefig command. Complete docstrings below. I didn't write the landscape support for PS/EPS (there is none currently for png), but I think the following incantation is what you are looking for from matplotlib.matlab import * figure(figsize=(11, 8.5)) plot([1,2,3]) savefig('temp.ps', orientation='landscape') show() Docstring: figure(num = 1, figsize=(8, 6), dpi=80, facecolor='w', edgecolor='k') Create a new figure and return a handle to it If figure(num) already exists, make it active and return the handle to it. figure(1) figsize - width in height x inches; defaults to rc figure.figsize dpi - resolution; defaults to rc figure.dpi facecolor - the background color; defaults to rc figure.facecolor edgecolor - the border color; defaults to rc figure.edgecolor rcParams gives the default values from the .matplotlibrc file 3 >>> savefig? Type: function Base Class: <type 'function'> String Form: <function savefig at 0x414504fc> Namespace: Interactive File: /usr/local/lib/python2.3/site-packages/matplotlib/matlab.py Definition: savefig(*args, **kwargs) Docstring: def savefig(fname, dpi=150, facecolor='w', edgecolor='w', orientation='portrait'): Save the current figure to filename fname. dpi is the resolution in dots per inch. Output file types currently supported are jpeg and png and will be deduced by the extension to fname facecolor and edgecolor are the colors os the figure rectangle orientation is either 'landscape' or 'portrait' - not supported on all backends; currently only on postscript output. Hope this helps, JDH |