-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add deprecation for colormaps #20853
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
A flaw in our plans is that 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. |
As written in #23668 (review), it's ok to postpone |
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? |
@jklymak I've rewritten the "Target state" and "Transition path" paragraphs above. Is that clearer now? |
This is the next stage of matplotlib#20853.
This is the next stage of matplotlib#20853.
This is the next stage of matplotlib#20853.
The deprecation was bumped in #24846 for 3.7; this now moves to 3.9 for the final part. |
Colormaps can be still accessed in version 3.7.0 using the following syntax: Issue #19609 mentions this disambiguity, but does not really address my question. |
The deprecation warning says to use |
matplotlib/lib/matplotlib/__init__.py Line 1497 in 4f65e66
|
Note that matplotlib 3.8 (due out soon) will ship with our own type stubs (for the first time) that will help clarify this to type checkers. matplotlib/lib/matplotlib/__init__.pyi Line 114 in 4f65e66
Colormaps in the registry are actually a dynamic set of things, that can be changed at run time (and many such as the Note that most of this implementation was done before static type checking was a thing in Python, and well I have personally invested time into trying to make it better and more usable, there certainly are still (and will be for the foreseeable future) rough edges of the static type checkability of Matplotlib. (@timhoffm, I think the lack of a |
( |
Sorry for sending a grumpy message, and thank you for your thoughtful response. |
Hmmm, my editor integration (powered by pyright), and mypy/pyright cli with default settings at least, are perfectly happy with it: import matplotlib
from typing import reveal_type
col = matplotlib.colormaps
reveal_type(col) Mypy cli:
Pyright cli:
(Editor is literally just inlined version of pyright CLI) Not sure what pycharm is using to do type checking, but those two are generally considered the biggest ones... |
`get_cmap` is deprecated, see matplotlib/matplotlib#20853 Co-authored-by: Tanguy Fardet <tanguyfardet@protonmail.com> Reviewed-on: https://codeberg.org/tfardet/mpl_chord_diagram/pulls/43 Reviewed-by: Guillermo Pérez-Hernández <gph82@noreply.codeberg.org>
Re-upping this. I just came across some old code that I'm updating. Is |
There are no concrete plans to remove |
I believe this is complete with the merging of #26965. |
(Edited) for anyone daft like me to replace:
you can do the following:
|
Would have been nice to see deprecation warnings for |
Yes, it would have been nice... and it seems related to Python choices for default warnings, though: Now that we manually enabled DeprecationWarnings, we also found out that distutils is being deprecated.... which we are currently using to account for deprecated APIs... |
* Use probe_update_start to control the probe update in WASP * Add WASP tests with probe_update_start * Update WASP publication * Remove get_cmap as suggested in matplotlib/matplotlib#20853 * Handle colormap registration in different versions of matplotlib * Skip FFT filter tests if Numpy < 2.0 --------- Co-authored-by: Benedikt Daurer <benedikt.daurer@diamond.ac.uk>
* Use probe_update_start to control the probe update in WASP * Add WASP tests with probe_update_start * Update WASP publication * Remove get_cmap as suggested in matplotlib/matplotlib#20853 * Handle colormap registration in different versions of matplotlib * Skip FFT filter tests if Numpy < 2.0 --------- Co-authored-by: Benedikt Daurer <benedikt.daurer@diamond.ac.uk>
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 orderregister_cmap(name, cmap)
where name is optional.Target state
matplotlib.cm
colormap functions should eventually be removed:matplotlib.cm.register_cmap(...)
- usempl.colormaps.register(...)
insteadmatplotlib.cm.unregister_cmap(...)
- usempl.colormaps.unregister(...)
insteadmatplotlib.cm.get_cmap(name)
- usempl.colormaps[name]
instead, followed by.resampled()
if needed to coverget_cmap(lut=...)
.I'm open for discussion if we keep the pyplot functions or replace them with the registry as well.Suggestion on pyplot:plt.register_cmap
- usempl.colormaps.register(...)
instead. - This is a fundamental operation and IMHO beyond the scope ofpyplot
plt.get_cmap()
- This is too widely used to be removed. But eventually remove itslut
parameter in favor ofplt.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: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.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)
The text was updated successfully, but these errors were encountered: