Getting an RGB value from a colormap
![](https://secure.gravatar.com/avatar/3fa4c407652670543ec9dac9442119d2.jpg?s=120&d=mm&r=g)
Hi, I'd like to use the colormap interface in a different way than it's used in plotting images. I am plotting a series of curves (using regular old plot), each of which corresponds to the behavior of a biological circuit under a different level of "inducer", ranging from around 0-100. I want to assign the color of each line according to the inducer value, and I want to try out different colormaps to see which I like best. All I really want is a method that, for a given colormap (jet, pink, hot, hsv, etc), takes a number between 0,1 as input and returns the corresponding RGB value, which I can then use a 'color' argument in a plotting command. (I was sort of hoping that the colormap object itself would provide such a method but I couldn't find any description of it's interface). Any ideas? Thanks, -mike
![](https://secure.gravatar.com/avatar/73f4e1ffd23622a339c1c9303615d7fe.jpg?s=120&d=mm&r=g)
"mike" == mike cantor <mcantor@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#LinearSegmentedColo... "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
participants (2)
-
John Hunter
-
mike cantor