-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Confusing (broken?) colormap name handling #5087
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
Seems like the issue is coming up in the matplotlib/lib/matplotlib/pyplot.py Lines 2072 to 2078 in bb75f73
The name you pass to that function is only used to grab the colormap, but this doesn't account for the fact that in the internal list of colormaps ( cmap_d in cm.py) the name can be different than the name associated with the colormap object. A workaround is to just set the rcParam image.cmap yourself:
plt.rcParams['image.cmap']='my_cmap_name' |
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! |
This is still broken. Current The linked PR above was closed in favour of #18503 which introduced those new names, but it does not appear to have corrected this issue. I'm going to ping @timhoffm and @greglucas who were working on that refactor whether they have opinions for how to proceed here. |
Yeah, this seems like a corner case for whether we want to allow differing registered names from colormap names. I think we probably do, as evidenced by the test case I gave, where maybe I want to get I think @ianhi was correct and the issue was setting the rc parameters to the incorrect value. I just pushed up a new PR with a quick fix to allow that. I think the validation in other parts of the colormap update is still correct and the new PR just uses a different way to set the rc parameter. |
Consider the following example in which one creates and registers a new colormap and attempt to use it with the
pyplot
interface.Everything OK so far. Note the difference in the names
some_cmap_name
andmy_cmap_name
. Now when we try to use the new colormap things start to go wrong.As seen from the error message, it's
my_cmap.name (=some_cmap_name)
that is looked up instead of the registered colormap name,my_cmap_name
. Manually looking upmy_cmap_name
works just fine:For this to work as I had expected, one has to make sure that the colormap name and the registered name are the same due to some sort of "double internal name lookup tables" in matplotlib.
I found this problem to be very confusing at first since I imported a colormap from another module, registered it, and tried to use it with no luck, e.g. something like:
at which point, I expected to be able to refer to my newly registered colormap by the name
my_cmap_name
.The text was updated successfully, but these errors were encountered: