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

Colormaps having odd naming when converted internally #84

Open
cvanelteren opened this issue Feb 19, 2025 · 2 comments
Open

Colormaps having odd naming when converted internally #84

cvanelteren opened this issue Feb 19, 2025 · 2 comments

Comments

@cvanelteren
Copy link
Contributor

Colormaps are converted internally and renamed. This caused a bug in #82 but is recently fixed in main. The issue can be seen from

import ultraplot as plt
for name, cmap in plt.colormaps.items():
    print(f"{cmap.name=} {name=}")
# prints  for example cmap.name='_BR_copy' name='br'

The name of the colormaps if correct, and hence all the functions work correctly. I have the intuition by integration mpl's colormaps and ultraplot's colormaps that this renaming is performed to avoid potential naming collision. I believe this would be unnecessary and is rather confusing.

The relevant code can be found in colors.py

 def _make_name(self, suffix=None):
        """
        Generate a default colormap name. Do not append more than one
        leading underscore or more than one identical suffix.
        """
        name = self.name
        name = name or ""
        if name[:1] != "_":
            name = "_" + name
        suffix = suffix or "copy"
        suffix = "_" + suffix
        if name[-len(suffix) :] != suffix:
            name = name + suffix
        return name
@cvanelteren
Copy link
Contributor Author

Note that the internal lookup for colormaps ignore cases.

@cvanelteren
Copy link
Contributor Author

For the user this may never cause an issue unless the explicit cmap.name is used. I don't really know why the maps are internally converted to this plus the suffix, but I think it should be removed.

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

No branches or pull requests

1 participant