Visitar URL original
Matplotlib v3.9 compatibility by C-Achard · Pull Request #3394 · DeepLabCut/DeepLabCut · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9cc1d18
Add Matplotlib colormap compatibility shim
C-Achard Jul 13, 2026
9518b9d
Allow custom warning stacklevel in deprecated
C-Achard Jul 13, 2026
bd7fdbb
Use shared get_colormap helper everywhere
C-Achard Jul 13, 2026
4bf4921
Merge branch 'main' into cy/init-mpl-version-change
C-Achard Jul 16, 2026
a5d5221
Merge remote-tracking branch 'upstream/main' into cy/init-mpl-version…
deruyter92 Aug 9, 2026
d5945cc
Fix get_colormap_names() legacy fallback to call _legacy_get_colormap…
deruyter92 Aug 9, 2026
d77d4f8
update version for "deprecated since .." warning
deruyter92 Aug 9, 2026
5e739e2
Add name override to deprecated() for legacy shim warnings
deruyter92 Aug 9, 2026
e6cfac6
Rename matplotlib_future_mode.py → matplotlib_compat.py
deruyter92 Aug 9, 2026
d9288fc
add tests for matplotlib compat layer
deruyter92 Aug 9, 2026
350e209
Import matplotlib.cm explicitly in the compat layer
C-Achard Sep 4, 2026
54ac2ac
Prevent duplicate legacy colormap registration
C-Achard Sep 4, 2026
b1c97fb
Route all plt.get_cmap calls throught the compat layer
C-Achard Sep 4, 2026
c1cf140
Use compat helper to clear matplotlib artists
C-Achard Sep 4, 2026
0e4a691
Patch matplotlib's Axes logger by name
C-Achard Sep 4, 2026
d3472c3
Test the name and stacklevel options of @deprecated
C-Achard Sep 4, 2026
0be8837
Expand matplotlib compat test coverage
C-Achard Sep 4, 2026
fe9d488
Remove unused compat helpers
C-Achard Sep 4, 2026
304bcc6
Remove unecessary tests
C-Achard Sep 4, 2026
aa007f6
Rename matplotlib compat module to utils
C-Achard Sep 4, 2026
0584d53
Replace matplotlib_compat colormap helpers
C-Achard Sep 4, 2026
1c15225
Simplify Matplotlib axes logger helper
C-Achard Sep 4, 2026
8a0ea71
Fix Matplotlib artist iteration
C-Achard Sep 4, 2026
426943f
Merge branch 'dev' into cy/init-mpl-version-change
deruyter92 Sep 8, 2026
31380eb
Merge branch 'dev' into cy/init-mpl-version-change
deruyter92 Sep 8, 2026
de29151
Merge branch 'dev' into cy/init-mpl-version-change
deruyter92 Sep 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename matplotlib compat module to utils
Replaces `deeplabcut.utils.matplotlib_compat` with `matplotlib_utils` and narrows it to the shared `silence_axes_logger` helper plus `AXES_LOGGER_NAME`. Removes the old colormap and artist-removal compatibility helpers and rewrites tests to target the new module and its logger behavior.
  • Loading branch information
C-Achard committed Sep 4, 2026
commit aa007f6fbb400e5b0390e75f906b669741c936d9
67 changes: 0 additions & 67 deletions deeplabcut/utils/matplotlib_compat.py

This file was deleted.

38 changes: 38 additions & 0 deletions deeplabcut/utils/matplotlib_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# DeepLabCut Toolbox (deeplabcut.org)
# © A. & M.W. Mathis Labs
# https://github.com/DeepLabCut/DeepLabCut
#
# Please see AUTHORS for contributors.
# https://github.com/DeepLabCut/DeepLabCut/blob/main/AUTHORS
#
# Licensed under GNU Lesser General Public License v3.0
#
"""Small Matplotlib helpers shared across DeepLabCut."""

from __future__ import annotations

import logging

# Matplotlib builds this logger with ``logging.getLogger(__name__)`` in
# ``matplotlib/axes/_axes.py``, so the name is enough to reach it.
AXES_LOGGER_NAME = "matplotlib.axes._axes"


def silence_axes_logger(level: int | str = "ERROR") -> None:
"""Raise the log level of Matplotlib's ``Axes`` logger.

Suppresses the chatty per-artist messages Matplotlib emits while drawing,
most notably the invalid-color warnings raised during 3D plotting.

Reaches the logger by name rather than importing ``_log`` from the private
``matplotlib.axes._axes`` module. This is the same logger object, not a
parallel one: Matplotlib creates it with ``logging.getLogger(__name__)``,
and the logging manager returns that same instance here -- or, if this runs
first, hands Matplotlib the instance created here. Import order therefore
does not matter.

Args:
level: Any level accepted by ``logging.Logger.setLevel``.
"""
logging.getLogger(AXES_LOGGER_NAME).setLevel(level)
176 changes: 0 additions & 176 deletions tests/utils/test_matplotlib_compat.py

This file was deleted.

56 changes: 56 additions & 0 deletions tests/utils/test_matplotlib_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#
# DeepLabCut Toolbox (deeplabcut.org)
# © A. & M.W. Mathis Labs
# https://github.com/DeepLabCut/DeepLabCut
#
# Please see AUTHORS for contributors.
# https://github.com/DeepLabCut/DeepLabCut/blob/main/AUTHORS
#
# Licensed under GNU Lesser General Public License v3.0
#
"""Tests for ``deeplabcut.utils.matplotlib_utils``."""

from __future__ import annotations

import logging

import pytest

from deeplabcut.utils import matplotlib_utils as mu


@pytest.fixture
def axes_logger():
"""Yield Matplotlib's Axes logger, restoring its level afterwards."""
logger = logging.getLogger(mu.AXES_LOGGER_NAME)
original = logger.level
yield logger
logger.setLevel(original)


def test_axes_logger_name_matches_matplotlibs_own_logger():
"""``AXES_LOGGER_NAME`` must resolve to the logger Matplotlib actually uses.

``silence_axes_logger`` reaches that logger by name instead of importing
``_log``, so a module rename upstream would silently stop suppressing
messages rather than raising. This is the assertion that turns such a
rename back into a loud failure, and the one place where importing the
private module is the point.
"""
from matplotlib.axes._axes import _log

assert logging.getLogger(mu.AXES_LOGGER_NAME) is _log


def test_silence_axes_logger_sets_the_level(axes_logger):
axes_logger.setLevel(logging.DEBUG)

mu.silence_axes_logger()

assert axes_logger.level == logging.ERROR


def test_silence_axes_logger_accepts_an_explicit_level(axes_logger):
mu.silence_axes_logger(logging.CRITICAL)

assert axes_logger.level == logging.CRITICAL