Once you've created a Colormap
instance, all you need to do is call it with a float value between 0 and 1, and it will return a tuple containing the corresponding RGBA values:
>>> gradient2n(0.5)
(1.0, 0.49803921568627452, 0.49803921568627452, 1.0)
There's no straightforward way of representing arbitrary colors as 'human-readable' names - to represent 8bit color you would need 16,777,216 distinct names! However, you can easily convert the RGBA values to a hex string using matplotlib.colors.rgb2hex
.
So your overall function might look like:
from matplotlib.colors import rgb2hex
def colors_at_breaks(cmap, breaks):
return [rgb2hex(cmap(bb)) for bb in breaks]
For example:
>>> colors_at_breaks(gradient2n, breaks)
['#ffffff', '#ffbfbf', '#ff7f7f', '#ff3f3f', '#ff0000']