Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib: Get the colormap array

I am new to matplotlib, and have get stuck in colormaps.

In matplotlib how do I get the whole array of RGB colors for a specific colormap, let's say for "hot". For example if I was in MATLAB I would have just done this:

# in matlab
c = hot(256);
disp(c)

Any ideas?

like image 296
ahmadh Avatar asked Mar 03 '12 03:03

ahmadh


1 Answers

You can look up the values by calling the colormap as a function, and it accepts numpy arrays to query many values at once:

In [12]: from matplotlib import cm
In [13]: cm.hot(range(256))
Out[13]: 
array([[ 0.0416    ,  0.        ,  0.        ,  1.        ],
       [ 0.05189484,  0.        ,  0.        ,  1.        ],
       [ 0.06218969,  0.        ,  0.        ,  1.        ],
       ..., 
       [ 1.        ,  1.        ,  0.96911762,  1.        ],
       [ 1.        ,  1.        ,  0.98455881,  1.        ],
       [ 1.        ,  1.        ,  1.        ,  1.        ]])
like image 200
Jouni K. Seppänen Avatar answered Dec 27 '22 22:12

Jouni K. Seppänen