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

Update colormap registration #845

Closed
ns-rse opened this issue May 16, 2024 · 0 comments · Fixed by #846
Closed

Update colormap registration #845

ns-rse opened this issue May 16, 2024 · 0 comments · Fixed by #846
Assignees
Labels
configuration Plotting Issues pertaining to the plotting class

Comments

@ns-rse
Copy link
Collaborator

ns-rse commented May 16, 2024

Matplotlib 3.9 will see the deprecation of matplotlib.cm.register_cmap() which we currently use as plt.register_cmap() in topostats/init.py...

"""Topostats."""

from importlib.metadata import version

import matplotlib.pyplot as plt
import snoop

from .logs.logs import setup_logger
from .theme import Colormap

LOGGER = setup_logger()

release = version("topostats")
__version__ = ".".join(release.split("."[:2]))

plt.register_cmap(cmap=Colormap("nanoscope").get_cmap())
plt.register_cmap(cmap=Colormap("gwyddion").get_cmap())

Whilst the function name has been deprecated the functionality hasn't and the commit that covers this details what function to use instead...

Removal of top-level cmap registration and access functions in ``mpl.cm``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As part of the `multi-step refactoring of colormap registration
<https://github.com/matplotlib/matplotlib/issues/20853>`_, the following functions have
been removed:

- ``matplotlib.cm.get_cmap``; use ``matplotlib.colormaps[name]`` instead if you
  have a `str`.

  Use `matplotlib.cm.ColormapRegistry.get_cmap` if you have a `str`, `None` or a
  `matplotlib.colors.Colormap` object that you want to convert to a `.Colormap`
  object.
- ``matplotlib.cm.register_cmap``; use `matplotlib.colormaps.register
  <.ColormapRegistry.register>` instead.
- ``matplotlib.cm.unregister_cmap``; use `matplotlib.colormaps.unregister
  <.ColormapRegistry.unregister>` instead.
- ``matplotlib.pyplot.register_cmap``; use `matplotlib.colormaps.register
  <.ColormapRegistry.register>` instead.

The `matplotlib.pyplot.get_cmap` function will stay available for backward
compatibility.

I think the replacement required is therefore...

from matplotlib import colormaps

colormaps.register(cmap=Colormap("nanoscope").get_cmap())
colormaps.register(cmap=Colormap("gwyddion").get_cmap())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
configuration Plotting Issues pertaining to the plotting class
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant