# 'Inverting' a colormap (was "Next problem: pixel-to-pixel alpha variation")

No one has a shareable code example of how to invert a colormap to an RGB array?

DG

···

--- On Tue, 9/9/08, David Goldsmith <d_l_goldsmith@...9...> wrote:

eventually ... I'd like to do what John implies
is possible, i.e., "invert" a cm back to its RGB
table - John (or anyone) can you short-cut the learning
process for me w/ a code example of how to do this?
Thanks!

DG

eventually ... I'd like to do what John implies
is possible, i.e., "invert" a cm back to its RGB
table - John (or anyone) can you short-cut the learning
process for me w/ a code example of how to do this?
Thanks!

DG

No one has a shareable code example of how to invert a colormap to an RGB array?

Is this what you are looking for? (outputs RGBA but just override the
alpha or extract the RGB part)

In [9]: import matplotlib.cm as cm

In [10]: x = np.arange(0, 1, 0.1)

In [11]: print cm.jet(x)
[[ 0. 0. 0.5 1. ]
[ 0. 0. 0.9456328 1. ]
[ 0. 0.3 1. 1. ]
[ 0. 0.69215686 1. 1. ]
[ 0.16129032 1. 0.80645161 1. ]
[ 0.49019608 1. 0.47754586 1. ]
[ 0.80645161 1. 0.16129032 1. ]
[ 1. 0.77051561 0. 1. ]
[ 1. 0.40740741 0. 1. ]
[ 0.9456328 0.02977487 0. 1. ]]

···

On Tue, Sep 16, 2008 at 2:40 PM, David Goldsmith <d_l_goldsmith@...9...> wrote:

--- On Tue, 9/9/08, David Goldsmith <d_l_goldsmith@...9...> wrote:

Excellent, thanks!!!

DG

···

--- On Tue, 9/16/08, John Hunter <jdh2358@...287...> wrote:

From: John Hunter <jdh2358@...287...>
Subject: Re: [Matplotlib-users] 'Inverting' a colormap (was "Next problem: pixel-to-pixel alpha variation")
To: d_l_goldsmith@...9...
Cc: matplotlib-users@lists.sourceforge.net
Date: Tuesday, September 16, 2008, 12:46 PM
On Tue, Sep 16, 2008 at 2:40 PM, David Goldsmith > <d_l_goldsmith@...9...> wrote:
> --- On Tue, 9/9/08, David Goldsmith > <d_l_goldsmith@...9...> wrote:
>
>> eventually ... I'd like to do what John
implies
>> is possible, i.e., "invert" a cm back to
its RGB
>> table - John (or anyone) can you short-cut the
learning
>> process for me w/ a code example of how to do
this?
>> Thanks!
>>
>> DG
>
> No one has a shareable code example of how to invert a
colormap to an RGB array?

Is this what you are looking for? (outputs RGBA but just
override the
alpha or extract the RGB part)

>In [9]: import matplotlib.cm as cm

In [10]: x = np.arange(0, 1, 0.1)

In [11]: print cm.jet(x)
[[ 0. 0. 0.5 1. ]
[ 0. 0. 0.9456328 1. ]
[ 0. 0.3 1. 1. ]
[ 0. 0.69215686 1. 1. ]
[ 0.16129032 1. 0.80645161 1. ]
[ 0.49019608 1. 0.47754586 1. ]
[ 0.80645161 1. 0.16129032 1. ]
[ 1. 0.77051561 0. 1. ]
[ 1. 0.40740741 0. 1. ]
[ 0.9456328 0.02977487 0. 1. ]]