Skip to content
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

[MNT]: Make the colormap naming work with any capitalization #28150

Closed
paulcbogdan opened this issue Apr 29, 2024 · 2 comments
Closed

[MNT]: Make the colormap naming work with any capitalization #28150

paulcbogdan opened this issue Apr 29, 2024 · 2 comments

Comments

@paulcbogdan
Copy link

Summary

When selecting a colormap, I often find myself not using the proper capitalization. For example, I may reference "spectral" when it should be "Spectral" or I may reference "Seismic" when it should be "seismic" (official colormap examples). Could we do some fix that allows any case to work?

Proposed fix

Perhaps I'm just missing the logic behind why some are capitalized whereas others are not, but could we just define duplicate versions of the colormap either a capitalized first letter or a lowercase first letter? Something like this could be as simple as adding plt.cm.spectral = plt.cm.Spectral and the like wherever the colormaps are defined? If someone knows a better solution that doesn't require doing this for all the named colormaps, that would be better. I presume there's no easy way to just do it with .lower() or so.

@timhoffm
Copy link
Member

I feel making colormap names case insensitve in general is too permissive.

  • Most colormap names are all-lowercase, which seems fine.
  • The color-combination maps like "RdBu" use capitalization to distinguish the parts "rdbu" would be less readable.
  • Outliers are "Wistia", "Spectral", "CMRmap" and some qualitative colormaps.

could we just define duplicate versions of the colormap either a capitalized first letter or a lowercase first letter? Something like this could be as simple as adding plt.cm.spectral = plt.cm.Spectral and the like wherever the colormaps are defined?

It's not that simple, because of cmap = plt.cm.spectral; cmap.name == "Spectral". This would add confusion on another level. We'd have to add a copy with the new name. But then you get also all the duplicates in the listings. Note also that there's the plt.cm.[name] as well as the colormap registry plt.colormaps the latter could do aliasing on lookup but that's another level of complexity.

I think, it's best to live with the inconsistency.

@paulcbogdan
Copy link
Author

Fair enough, I wasn't aware of this "Note also that there's the plt.cm.[name] as well as the colormap registry plt.colormaps...". Thanks anyways for reading my suggestion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants