-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
colormaps don't have getters for under, over, bad colors. #16075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Actually I think the setters should not exist (see #14645)... |
Thanks. |
@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). |
Not sure I follow. By default you definitely want a color if the mapped value is over vmax. |
For sure, but currently I can't tell apart if |
import matplotlib.pyplot as plt
import numpy as np
cmap = plt.get_cmap('cividis')
# the following will return True since set_under was not used to set "under" color
np.allclose(cmap(0), cmap(-np.inf)) # True
cmap.set_under('w')
np.allclose(cmap(0), cmap(-np.inf)) # False
# similarly for set_over ...
np.allclose(cmap(255), cmap(np.inf)) # True
cmap.set_under('k')
np.allclose(cmap(255), cmap(np.inf)) # False |
Uh oh!
There was an error while loading. Please reload this page.
Bug report
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.Code for reproduction
If adding getters (for under, over, bad colors) for the colormaps sounds like a good improvement, i would be interested in submitting a PR.
Actual outcome
Expected outcome
Matplotlib version
print(matplotlib.get_backend())
):The text was updated successfully, but these errors were encountered: