[SciPy-user] [Matplotlib-users] Getting an RGB value from a colormap
John Hunter
jdhunter at ace.bsd.uchicago.edu
Tue Mar 7 15:49:45 EST 2006
>>>>> "mike" == mike cantor <mcantor at stanford.edu> writes:
mike> Hi, I'd like to use the colormap interface in a different
mike> way than it's used in plotting images. I am plotting a
mike> series of curves (using regular old plot), each of which
mike> corresponds to the behavior of a biological circuit under a
mike> different level of "inducer", ranging from around 0-100. I
mike> want to assign the color of each line according to the
mike> inducer value, and I want to try out different colormaps to
mike> see which I like best.
mike> All I really want is a method that, for a given colormap
mike> (jet, pink, hot, hsv, etc), takes a number between 0,1 as
mike> input and returns the corresponding RGB value, which I can
mike> then use a 'color' argument in a plotting command. (I was
In [6]: import matplotlib.cm as cm
In [7]: cm.jet(.5)
Out[7]: (0.49019607843137247, 1.0, 0.47754585705249841, 1.0)
mike> sort of hoping that the colormap object itself would provide
mike> such a method but I couldn't find any description of it's
mike> interface).
The class documentation is available at
http://matplotlib.sourceforge.net/classdocs.html
in particular, take a look at
http://matplotlib.sourceforge.net/matplotlib.colors.html#LinearSegmentedColormap
"jet" in the example above, is an instance of the
LinearSegmentedColormap colormap class, and the __call__ method
returns the data you are interested in for scalars or sequences.
JDH
More information about the SciPy-User
mailing list