Skip to content

Add deprecation for colormaps #20853

Closed
Closed

Description

@QuLogic

This is tracking for the next stage of the colormap registry, pulled out of the original PR so that it doesn't get lost. (Originally written by @timhoffm)

Overall goal

The registry is a more natural structure for managing colormaps. We have data and corresponding functions that are tightly related. IMHO it's a much nicer API for the user and easier to extend. And we get rid of some API quirks in the functions like get_cmap(.. lut=...) or the parameter order register_cmap(name, cmap) where name is optional.

Target state

  • the matplotlib.cm colormap functions should eventually be removed:
    • matplotlib.cm.register_cmap(...) - use mpl.colormaps.register(...) instead
    • matplotlib.cm.unregister_cmap(...) - use mpl.colormaps.unregister(...) instead
    • matplotlib.cm.get_cmap(name) - use mpl.colormaps[name] instead, followed by .resampled() if needed to cover get_cmap(lut=...).
  • I'm open for discussion if we keep the pyplot functions or replace them with the registry as well. Suggestion on pyplot:
    • eventually remove plt.register_cmap - use mpl.colormaps.register(...) instead. - This is a fundamental operation and IMHO beyond the scope of pyplot
    • keep plt.get_cmap() - This is too widely used to be removed. But eventually remove its lut parameter in favor of plt.get_cmap().resampled().

Transition path

While I would like to eventually remove the matplotlib.cm functions, I propose a prolonged transition path because they are quite fundamental functions also used in third party libraries:

  • For 3.5: introduce the registry as is in this PR; discourage the cm functions. This is to see if we have missed something important in the design and get user feedback. - Maybe we should declare the registry experimental.
  • For 3.6: Introduce a pending deprecation on all functions that we want to eventually remove. This is the time where all downstream libraries should start switching to using the registry.
  • For 3.7 (or later): Deprecate all the functions we want to remove.
  • For 3.9 (or later): Remove all the functions we want to remove.

I strongly advocate to introduce this PR in 3.5. If everything goes well, we don't need modifications (only extensions) to the registry, which means that downstream libraries would have 3.5 as a minimum dependency when they switch to the registry.

On read-only colormaps

The registry colormap access already returns copies of the colormaps and by that implements the change to get_cmap, which is scheduled to take effect in 3.6 (#19766). He can be quicker here, because the new API does not have to maintain backward compatibility for the deprecation period.
Other than that, the registry is independent of cmap mutability.

Originally posted by @timhoffm in #18503 (comment)

Activity

  1. added this to the v3.6.0 milestone on Aug 18, 2021
  2. tacaswell commented on Aug 18, 2022

    @tacaswell
    Member

    A flaw in our plans is that get_cmap take as second lut argument which we do not have a public API to do. There is a private API for this (cmap._resample() via #5283). I think this is show-stopping to get this done for 3.6.

    I'm still going to try and get the PR to do all of this done, but am skeptical we want to force it through.

  3. timhoffm commented on Aug 19, 2022

    @timhoffm
    Member

    As written in #23668 (review), it's ok to postpone get_cmap to 3.7 if it's too complicated.

  4. jklymak commented on Aug 19, 2022

    @jklymak
    Member

    Given that we are linking this issue in the What's New, I'd really appreciate it if the issue was edited to explicitly explain what is being deprecated, and what is replacing it. I've been following this peripherally, and even for me, the comment above, cut and pasted from elsewhere, is too vague for me to understand the roadmap, so I fear that our users are not going to understand it either. Or in #23668 or whatever follows from it, lay it out in the what's new and don't refer to a cryptic issue?

  5. timhoffm commented on Aug 19, 2022

    @timhoffm
    Member

    @jklymak I've rewritten the "Target state" and "Transition path" paragraphs above. Is that clearer now?

  6. modified the milestones: v3.6.0, v3.7.0 on Aug 25, 2022
  7. QuLogic commented on Jan 7, 2023

    @QuLogic
    MemberAuthor

    The deprecation was bumped in #24846 for 3.7; this now moves to 3.9 for the final part.

  8. removed this from the v3.7.0 milestone on Jan 7, 2023
  9. 19 remaining items

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions