Michael Hearne wrote:
> I'm trying to replicate the color-mapping behavior of the GMT package 
> with matplotlib/basemap and the imshow() function, and have run into a 
> problem.
> 
> Using GMT you can assign colors to ranges of Z values, so that (for 
> example), Z values between 0 and 50 are given a color interpolated 
> between  (0,0,255) (blue) and (255,0,0) (red).  There have been various 
> versions of a function called gmtColorMap() posted to this list.  I did 
> some experiments today, and as far as I can tell, this function only 
> reads the _color_ part of a GMT .cpt file, ignoring the Z values to 
> which those color ranges are assigned.  This isn't a problem as long as 
> you have a linear color scale.  However, if you have (as in my case) a 
> color scale assigned to non-linear ranges of values, it becomes a problem.
> 
> Is there a way with imshow() to assign ranges of colors to specific 
> ranges of Z values?
> 


Yes.  See examples/pylab_examples/image_masked.py for an example of 
BoundaryNorm.  The combination of a ListedColormap and a BoundaryNorm 
should provide exactly what you are describing.

Eric

> As a test, I created the attached python script, which reads in the 
> attached .cpt file.
> 
> For those of you not aware of the GMT color palette file format, in each 
> row you define two end points for your Z values, and two corresponding 
> RGB triplets.  In my simplified example, I have defined 8 ranges, and 
> assigned a single color to each range.  For example, the first two lines 
> in my color palette file looks like this:
> 
> 00000 255 255 255 00005 255 255 255
> 00005 255 255 000 00050 255 255 000
> 
> which can be interpreted to mean that any values between 0 and 5 (filled 
> in with zeros to make the columns line up), should be colored white.  
> Similarly, any values between 5 and 50 should be colored yellow.
> 
> 
> 
> 
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> ------------------------------------------------------------------------------
> SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
> The future of the web can't happen without you.  Join us at MIX09 to help
> pave the way to the Next Web now. Learn more and register at
> http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users


------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to