-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Modifying colormaps (as used in xarray) #16296
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
I guess its a fair question whether we should have ever provided |
Potential actionable things here are:
Worth mentionning that matplotlib does not even take over/under/bad too seriously itself. E.g. neither the
|
For the getters, see recent discussion in #16075. |
Isn't that |
No, because that gives a new colormap without the original over/under/bad settings.
It's also not really desired, since there needs to be a way to get the inbuilt colormap back even after modifications. |
Your second line looks like a bug to me. Why would setting over be sticky like that to the colormap name? |
Builtin colormaps are created once and stored globally in
Proposal for changesIMHO this needs some cleanup, which will include breaking changes (but OTOH I expect that not many people would be affected by the breaking).
|
I am 👍 on all of @timhoffm 's proposals. For 1) we should go with an API like named tuple of We will definitely need a transition period and a public way to set a replacement color map for a built in one. I am sure that we have significant use of plt.get_cmap('viridis').set_under('k')
plt.imshow(data, cmap='viridis') |
The replace() API is basically implemented (under a different name) at #14645 ;-) |
I have definitely messed myself up before by accidentally setting an under/over value somewhere early-on in a Jupyter notebook and been very confused why the cmaps I was using later were looking different than the builtin only to realize I'd made this very mistake! I'd be all for returning a copy of the colormaps when calling |
I see that I have now argued both sides of this (here being in favor of changing the behavior and in #16943 comments against changing the behavior). |
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help! |
Most of the above aspects are implemented by now:
The only open aspect is immutable colormaps. It would have been nice to have immutability designed in from the start. But that's not the world we're in. I'm inclined to say that enforcing immutability now would be too much of an API change compared to what we gain. The above changes already make it much more unlikely that changing an existing colormap will have unwanted side effects. I therefore close this issue as done. If there was still need for a discussion on immutable colormaps, please open a new ticket for that. |
xarray
's plotting functionality sometimes needs to turn a colormap into a discrete colormap. I came across this in fixing a bug pydata/xarray#3601 wherexarray
was ignoring the effects ofset_under()
, etc., which had been called on the colormap. We've fixed that problem, but ended up with this https://github.com/pydata/xarray/blob/ae6609b025d62a0d863869cbd16db167a8855167/xarray/plot/utils.py#L94-L105This works, but is not particularly elegant, and if there are any other properties of the original
cmap
that we want to keep, we'd have to copy them over explicitly. @dcherian asked me to see if anyone on here could suggest a better way of modifying acmap
into a discretecmap
?The text was updated successfully, but these errors were encountered: