Bug summary
colormaps don't have getters for under, over, bad colors (although the corresponding setters exist).
I am writing a function that accepts a colormap as an argument. I want to ensure that the colormap passed to the function has the same color for the "bad" and "under" conditions. The only way around this is to access "private" attributes cmap._rgba_under, cmap._rgba_bad as shown below.
Actually I think the setters should not exist (see #14645)...
I think you can do cmap(+np.inf) cmap(-np.inf) cmap(np.nan) to get the over/under/bad values, not sure if it warrants a separate API?
@anntzer perhaps it warrants a different API? The difference is distinguished when bad/under/over were not set at all. Querying the cmap for such cases will result with the default extreme colors even when these were never set by the cmap creator. With getters I expect to get the set value (if provided) or None (if these weren't set at all).
For sure, but currently I can't tell apart if set_over was called prior to that or I'm getting the default extreme value from the colormap. So by having a get_over that returns None if set_over was never called (or the input to set_over in the case it was called), I can distinguish between the two cases. This may prove useful for manipulating colormaps.
importmatplotlib.pyplotaspltimportnumpyasnpcmap=plt.get_cmap('cividis')
# the following will return True since set_under was not used to set "under" colornp.allclose(cmap(0), cmap(-np.inf)) # Truecmap.set_under('w')
np.allclose(cmap(0), cmap(-np.inf)) # False# similarly for set_over ...np.allclose(cmap(255), cmap(np.inf)) # Truecmap.set_under('k')
np.allclose(cmap(255), cmap(np.inf)) # False
Activity
anntzer commented on Jan 2, 2020
Actually I think the setters should not exist (see #14645)...
I think you can do cmap(+np.inf) cmap(-np.inf) cmap(np.nan) to get the over/under/bad values, not sure if it warrants a separate API?
pharshalp commented on Jan 2, 2020
Thanks.
MaozGelbart commented on Jan 28, 2020
@anntzer perhaps it warrants a different API? The difference is distinguished when bad/under/over were not set at all. Querying the cmap for such cases will result with the default extreme colors even when these were never set by the cmap creator. With getters I expect to get the set value (if provided) or None (if these weren't set at all).
jklymak commented on Jan 28, 2020
Not sure I follow. By default you definitely want a color if the mapped value is over vmax.
MaozGelbart commented on Jan 28, 2020
For sure, but currently I can't tell apart if set_over was called prior to that or I'm getting the default extreme value from the colormap. So by having a get_over that returns None if set_over was never called (or the input to set_over in the case it was called), I can distinguish between the two cases. This may prove useful for manipulating colormaps.
pharshalp commented on Jan 28, 2020
@MaozGelbart