[Matplotlib-users] New colormaps : Inferno, Viridis, ...

Eric Firing efiring at hawaii.edu
Sun Dec 13 12:55:35 EST 2015

On 2015/12/11 7:29 AM, Aston630 wrote:
> Hi,
> I wanted to try today the new exciting colormaps that come with the 1.5.0
> version of Matplotlib. I quickly discovered I could not use them the same as
> the previous colormaps. Indeed, in the past I used to do:
> import matplotlib as mpl
> cmap = mpl.cm.get_cmap("jet", nb_curves)
> # where cmap is LinearSegmentedColormap and from there get the colors the
> following way in order to
> # handle them the way I wanted for a set of curves or points or arrows
> etc... :
> colors = cmap(np.arange(nb_curves))
> Now with the new colormaps I do the same:
> import matplotlib as mpl
> cmap = mpl.cm.get_cmap("inferno", nb_curves)
> where cmap is now a ListedColormap and I cannot do what I used to do before.
> My first question would be : why this difference between old and new
> colormaps?

The LinearSegmentedColormap has quite a bit of machinery that is not 
needed when colormaps can be supplied as a long list of smoothly varying 
colors, for which ListedColormap is a natural fit.  What we missed, 
however, is a bug that you have found: the _resample() method of 
ListedColormap is not doing what it should do.

> Then, is there a way I could get a LinearSegmentedColormap from Inferno,
> Viridis, etc... ? This is really what I want.

Fixing _resample() would solve your problem; the only difference in 
usage between LinearSegmentedColormap and ListedColormap is in the 
inputs used to initialize them.  Once properly initialized, the color 
lookup mechanism is the same for both because it is inherited from the 
common base class.

Would you mind opening an issue on github for this?


> Thanks a lot for your time and considering this issue!
> --
> View this message in context: http://matplotlib.1069221.n5.nabble.com/New-colormaps-Inferno-Viridis-tp46530.html
> Sent from the matplotlib - users mailing list archive at Nabble.com.
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users

More information about the Matplotlib-users mailing list