Register Matplotlib Colormap

Viewed 703

I think this should work:

cm = matplotlib.colors.LinearSegmentedColormap.from_list('phases', ['g', 'y', 'c', 'm', 'b', 'r']
plt.register_cmap('phases', cm)

But when I type:

plt.cmap.phases

I get an attribute error. So clearly my cmap isn't being registered as I thought. But it's not clear why.

Ben

1 Answers

Your colormap gets registered. plt.cm only contains the built-in colormaps, not the registered ones.

To get the colormap use plt.cm.get_cmap('phases').
To set the colormap as default use plt.set_cmap('phases').
To get all built-in and registered colormaps use plt.colormaps().
To get only registered (not built-in) colormaps use [cm for cm in plt.colormaps() if cm not in dir(plt.cm)].

Related