Grabbing individual colors from color maps in matplotlib

Want an individual color from a color map in matplotlib?  You would think this would be easy (and it is as you will see below), but as I traversed the documentation, I could not find for the life of me how to do this.  After looking at various matplotlib functions, Rob and I finally found that it’s really simple (and apparently undocumented as far as we can tell).  Just choose your colormap (e.g. ‘jet’) and call it like a function with a value between 0 and 1: e.g.  This will return you the rgba 4-tuple that you can use for whatever.


  1. Vanessa · June 19, 2013

    Fantastic, thank you so much!! I’ve been trying to work this out for ages, thinking there must be something simpler than the kind of solutions people suggest. This is great! 🙂

  2. Geet · June 19, 2013

    Hi Vanessa, Glad this worked for you!

  3. Lakshmi Peesapati · December 3, 2013

    But the function is taking values beyond 1. What does that mean? For example if I give RdYlGn as my colormap string, blue is also getting included in the tuple. How can I just get red, green and a mixture of red and green (yellow)? How can I get pure red when I give a value of 0 and pure green when giving 1?


  4. Geet · December 3, 2013

    If I remember right, it’s kind of a ‘hybrid’ function. Between 0 and 1 you can get the whole spectrum, but then it also works ‘discretely’ to 255 I think. I’m not at a computer now, so I’m not for sure, but I’d be interested to know if that’s it.

    Geet Duggal

  5. Mike · May 22, 2015

    Awesome. Thank you! I too was trying to figure out how to do this, and Google led me here. 🙂 Exactly what I needed!

  6. Pingback: Python:Plot histogram with colors taken from colormap – IT Sprite

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s