Reverse colormap in matplotlib

I would like to know how to simply reverse the color order of a given colormap in order to use it with plot_surface.


Solution 1:

The standard colormaps also all have reversed versions. They have the same names with _r tacked on to the end. (Documentation here.)

Solution 2:

The solution is pretty straightforward. Suppose you want to use the "autumn" colormap scheme. The standard version:

cmap = matplotlib.cm.autumn

To reverse the colormap color spectrum, use get_cmap() function and append '_r' to the colormap title like this:

cmap_reversed = matplotlib.cm.get_cmap('autumn_r')