Skip to content

Initial matplotlib compat layer - #3394

Open
C-Achard wants to merge 10 commits into
mainfrom
cy/init-mpl-version-change
Open

Initial matplotlib compat layer#3394
C-Achard wants to merge 10 commits into
mainfrom
cy/init-mpl-version-change

Conversation

@C-Achard

Copy link
Copy Markdown
Collaborator

Scope

Adds a small compatibility layer for matplotlib, to be extended, which allows to safely transition towards more recent version and release the pin.

  • Wraps deprecated matplotlib calls into compatibility shims
  • Warns about upcoming deprecation
  • Can be extended as required until all matplotlib call sites are fixed

C-Achard added 3 commits July 13, 2026 15:42
Introduce a new utility module that centralizes colormap access, listing, registration, and unregistration across Matplotlib API versions. The new helpers prefer modern `matplotlib.colormaps` APIs when available and fall back to legacy `matplotlib.cm`/`pyplot` behavior, with deprecation markers on legacy paths to support the migration.
Adds a `stacklevel` argument to `deeplabcut.core.deprecation.deprecated()` and uses it when emitting `DLCDeprecationWarning`. This keeps the default behavior (`stacklevel=2`) while allowing wrapper/legacy shim layers to bump the level so warnings point to the real caller.
Replaced direct `plt.cm.get_cmap(...)` calls across visualization and plotting modules with `deeplabcut.utils.matplotlib_future_mode.get_colormap`. This centralizes colormap access, keeps behavior consistent across TensorFlow/PyTorch/GUI/3D paths, and aligns with Matplotlib future-mode compatibility.
@C-Achard C-Achard self-assigned this Jul 13, 2026
@C-Achard C-Achard added enhancement New feature or request backwards compatibility issues concerning prior to current versions labels Jul 13, 2026
@C-Achard C-Achard added this to the Release matplotlib pin milestone Jul 13, 2026
@deruyter92 deruyter92 modified the milestones: Release matplotlib pin, Refresh/bump core dependencies Jul 30, 2026
…_names

Previously it duplicated the legacy lookup inline (list(plt.colormaps())) instead of calling the @deprecated-decorated _legacy_get_colormap_names(), so the deprecation warning never fired on old Matplotlib installs, unlike register_colormap/unregister_colormap.
_legacy_register_colormap/_legacy_unregister_colormap/_legacy_get_colormap_names now report their public wrapper names (e.g. register_colormap) in deprecation warnings instead of the private helper name.
@deruyter92

Copy link
Copy Markdown
Collaborator

@C-Achard, great efforts, good plan. When working on this PR myself as well, I realized that adding a whole compat layer might not be necessary if the single solution plt.cm.get_cmap -> plt.get_cmap suffices (works for the full matplotlib quiver). The rest is anticipatory code which we currently may not need. But let's discus IRL, both have pro's and con's.

it might be helpful to merge #3430 first!

@deruyter92

Copy link
Copy Markdown
Collaborator

(pushed my additional changes now but feel free to revert)

@C-Achard

Copy link
Copy Markdown
Collaborator Author

adding a whole compat layer might not be necessary

There was definitely some future-proofing/extra caution in doing it this way, as I was concerned we may uncover other matplotlib-related issues that would arise/need to be added later. Hopefully the current layer is not too bloated/redundant, we can definitely trim if you think there is no need for it. I do agree it should be "disposable" ideally and removed later, so that would add some weight towards making it leaner, but at the same time it's already mostly there.

Perhaps, on the other hand, would you see any extensions to it that could be needed, or is it also clear for you that only the cmap getter is needed ? If yes then I would definitely not shrink it. If no we can remove some.

Let me know what you thinkl!

@C-Achard

C-Achard commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

I agree with all latest changes, thanks a lot for the testing additions

@C-Achard
C-Achard marked this pull request as ready for review August 13, 2026 13:53
@C-Achard
C-Achard requested a review from deruyter92 August 14, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backwards compatibility issues concerning prior to current versions enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants