What names can be used in plt.cm.get_cmap?

Timi picture Timi · Nov 15, 2017 · Viewed 22.7k times · Source

I have this code :

plt.scatter(data_projected[:,0],data_projected[:,1],c=digits.target
        ,edgecolors='none',alpha=0.5,cmap=plt.cm.get_cmap('nipy_spectral',10));    

My confusion comes from plt.cm.get_cmap('nipy_spectral',10). Sometimes there will be plt.cm.get_cmap('RdYlBu') instead.

Is the 'RdYlBu','nipy_spectral' the name of a color? And is there any other names to use instead?

Is there a list of all colors available?

I have read the document but it does not seem to help or I do not understand it.

Answer

ImportanceOfBeingErnest picture ImportanceOfBeingErnest · Nov 15, 2017

The first argument to plt.cm.get_cmap('nipy_spectral',10) is the name of a colormap. You can get a list of all available colormaps via

import matplotlib.cm
print(matplotlib.cm.cmap_d.keys())

or you may have a look at the colormap reference.