SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Michael G. <mg...@tx...> - 2006年11月29日 01:15:29
Hello,
I'm having trouble scaling the z-values for a filled contour plot. I 
would like to produce a series of plots like:
plot.contourf(x, y, z, 20, cmap=matplotlib.cm.RdBu_r)
but I would like there to be an absolute correspondence between a 
given z-value and a given color in the colormap no matter what the 
range of z-values for a particular plot. I thought the way to do this 
would be to use the norm keyword like:
normFunction = matplotlib.colors.normalize(vmin=minValue, maxValue)
plot.contourf(x, y, z, 20, norm=normFunction, cmap=matplotlib.cm.RdBu_r)
but this gives the error:
 File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
python2.4/site-packages/matplotlib/axes.py", line 4054, in contourf
 return ContourSet(self, *args, **kwargs)
 File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
python2.4/site-packages/matplotlib/contour.py", line 456, in __init__
 for level, level_upper, color in zip(lowers, uppers, self.tcolors):
AttributeError: ContourSet instance has no attribute 'tcolors'
Any suggestions?
Thanks,
Mike
From: Eric F. <ef...@ha...> - 2006年11月29日 18:57:16
Michael,
You have found a big bug that I introduced recently. Here is a patch, 
which I committed to svn: (watch out for line-breaking by the mailer)
--- lib/matplotlib/contour.py (revision 2899)
+++ lib/matplotlib/contour.py (working copy)
@@ -680,7 +680,12 @@
 if self.extend in ('both', 'max', 'min'):
 self.norm.clip = False
 self.set_array(self.layers)
- # self.tcolors will be set by the "changed" method
+ # self.tcolors are set by the "changed" method,
+ # but need to be set here also
+ # until some refactoring is done.
+ tcolors = [ (tuple(rgba),) for rgba in
+ self.to_rgba(self.cvalues, 
alpha=self.alpha)]
+ self.tcolors = tcolors
 def _process_linewidths(self):
 linewidths = self.linewidths
As the comments indicate, I think I will want to make more extensive 
changes, but this removes the immediate problem.
To get the result you want, however, I think that your approach using 
the norm will not work; maybe it should, but right now it doesn't. 
Instead, simply specify the contour levels that you want, like this:
contourf(x, y, z, linspace(minVal, maxVal, 20), cmap=matplotlib.cm.RdBu_r)
The option you were using, specifying only the number of contours, is 
designed for quick-and-dirty automatic contouring, not for fine control.
Eric
Michael Galloy wrote:
> Hello,
> 
> I'm having trouble scaling the z-values for a filled contour plot. I 
> would like to produce a series of plots like:
> 
> plot.contourf(x, y, z, 20, cmap=matplotlib.cm.RdBu_r)
> 
> but I would like there to be an absolute correspondence between a given 
> z-value and a given color in the colormap no matter what the range of 
> z-values for a particular plot. I thought the way to do this would be to 
> use the norm keyword like:
> 
> normFunction = matplotlib.colors.normalize(vmin=minValue, maxValue) 
> plot.contourf(x, y, z, 20, norm=normFunction, cmap=matplotlib.cm.RdBu_r)
> 
> but this gives the error:
> 
> File 
> "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/axes.py", 
> line 4054, in contourf
> return ContourSet(self, *args, **kwargs)
> File 
> "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/contour.py", 
> line 456, in __init__
> for level, level_upper, color in zip(lowers, uppers, self.tcolors):
> AttributeError: ContourSet instance has no attribute 'tcolors'
> 
> Any suggestions?
> 
> Thanks,
> Mike
> 
> 
> ------------------------------------------------------------------------
> 
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: Michael G. <mg...@tx...> - 2006年11月29日 19:59:46
That worked perfectly. Thanks!
-Mike
On Nov 29, 2006, at 11:56 AM, Eric Firing wrote:
> linspace(minVal, maxVal, 20)
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /