user308827 user308827 - 1 month ago 5
Python Question

Getting length of colormap in matplotlib

Is there a way to get length of matplotlib colormap?

cmap = mpl.colors.ListedColormap(['r', 'g', 'b', 'c'])


something like cmap.len()?

Answer

The list of colors is in member colors:

len(cmap.colors)