[Matplotlib-users] 'Inverting' a colormap (was "Next problem: pixel-to-pixel alpha variation") From: David Goldsmith - 2008-09-16 12:40 ```--- On Tue, 9/9/08, David Goldsmith 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? DG ```
 Re: [Matplotlib-users] 'Inverting' a colormap (was "Next problem: pixel-to-pixel alpha variation") From: John Hunter - 2008-09-16 12:46 ```On Tue, Sep 16, 2008 at 2:40 PM, David Goldsmith wrote: > --- On Tue, 9/9/08, David Goldsmith 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. ]] ```
 Re: [Matplotlib-users] 'Inverting' a colormap (was "Next problem: pixel-to-pixel alpha variation") From: David Goldsmith - 2008-09-16 13:37 ```Excellent, thanks!!! DG --- On Tue, 9/16/08, John Hunter wrote: > From: John Hunter > Subject: Re: [Matplotlib-users] 'Inverting' a colormap (was "Next problem: pixel-to-pixel alpha variation") > To: d_l_goldsmith@... > Cc: matplotlib-users@... > Date: Tuesday, September 16, 2008, 12:46 PM > On Tue, Sep 16, 2008 at 2:40 PM, David Goldsmith > wrote: > > --- On Tue, 9/9/08, David Goldsmith > 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. ]] ```