From 5aff5c5472314a2163a5ca9f3dd2fc91ff866bd0 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 4 Sep 2026 15:41:05 -0400 Subject: [PATCH] Backport PR #32104: Add font family to mismatched font weight warning --- lib/matplotlib/font_manager.py | 5 +++-- lib/matplotlib/tests/test_font_manager.py | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py index 82a5256eb68a..0ce526980da6 100644 --- a/lib/matplotlib/font_manager.py +++ b/lib/matplotlib/font_manager.py @@ -1663,8 +1663,9 @@ def _findfont_cached(self, prop, fontext, directory, fallback_to_default, break if best_font is not None and (_normalize_weight(prop.get_weight()) != _normalize_weight(best_font.weight)): - _log.warning('findfont: Failed to find font weight %s, now using %s.', - prop.get_weight(), best_font.weight) + _log.warning( + 'findfont: Failed to find font weight %s for %s, now using %s.', + prop.get_weight(), best_font.name, best_font.weight) if best_font is None or best_score >= 10.0: if fallback_to_default: diff --git a/lib/matplotlib/tests/test_font_manager.py b/lib/matplotlib/tests/test_font_manager.py index add063df9066..e9cac7caa5b8 100644 --- a/lib/matplotlib/tests/test_font_manager.py +++ b/lib/matplotlib/tests/test_font_manager.py @@ -615,9 +615,11 @@ def test_normalize_weights(): def test_font_match_warning(caplog): - findfont(FontProperties(family=["DejaVu Sans"], weight=750)) + font = 'DejaVu Sans' + findfont(FontProperties(family=[font], weight=750)) + expected = f'findfont: Failed to find font weight 750 for {font}, now using 700.' logs = [rec.message for rec in caplog.records] - assert 'findfont: Failed to find font weight 750, now using 700.' in logs + assert expected in logs def test_mutable_fontproperty_cache_invalidation():