From 2ca2b0a2b8c344ce51a6e03b2a0533c0e5d10f0e Mon Sep 17 00:00:00 2001 From: Steve Berardi Date: Tue, 13 Jan 2026 07:27:29 -0800 Subject: [PATCH 1/6] weight is int --- lib/matplotlib/backends/backend_svg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/backend_svg.py b/lib/matplotlib/backends/backend_svg.py index 0cb6430ec823..6b74363ff24f 100644 --- a/lib/matplotlib/backends/backend_svg.py +++ b/lib/matplotlib/backends/backend_svg.py @@ -1134,7 +1134,7 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None): font_style['font-style'] = prop.get_style() if prop.get_variant() != 'normal': font_style['font-variant'] = prop.get_variant() - weight = fm.weight_dict[prop.get_weight()] + weight = prop.get_weight() if weight != 400: font_style['font-weight'] = f'{weight}' From 2a39a8d7cc298d45e458bb8e3d17a35e56e1af12 Mon Sep 17 00:00:00 2001 From: Steve Berardi Date: Tue, 13 Jan 2026 07:29:10 -0800 Subject: [PATCH 2/6] comments --- lib/matplotlib/font_manager.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py index ab6b495631de..f85b08ffa8ff 100644 --- a/lib/matplotlib/font_manager.py +++ b/lib/matplotlib/font_manager.py @@ -23,7 +23,6 @@ # - font size is incomplete # - default font algorithm needs improvement and testing # - setWeights function needs improvement -# - 'light' is an invalid weight value, remove it. from __future__ import annotations @@ -748,10 +747,7 @@ def get_variant(self): def get_weight(self): """ - Set the font weight. Options are: A numeric value in the - range 0-1000 or one of 'light', 'normal', 'regular', 'book', - 'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold', - 'heavy', 'extra bold', 'black' + Return the font weight as an integer in the range 0-1000. """ return self._weight From ff683b812074b974a11236ef2072a63722a0c945 Mon Sep 17 00:00:00 2001 From: Steve Berardi Date: Tue, 13 Jan 2026 07:57:51 -0800 Subject: [PATCH 3/6] test --- lib/matplotlib/tests/test_backend_svg.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_backend_svg.py b/lib/matplotlib/tests/test_backend_svg.py index 2c64b7c24b3e..7864b3bb68bd 100644 --- a/lib/matplotlib/tests/test_backend_svg.py +++ b/lib/matplotlib/tests/test_backend_svg.py @@ -74,7 +74,8 @@ def test_bold_font_output(): ax.plot(np.arange(10), np.arange(10)) ax.set_xlabel('nonbold-xlabel') ax.set_ylabel('bold-ylabel', fontweight='bold') - ax.set_title('bold-title', fontweight='bold') + # set weight as integer to assert it's handled properly + ax.set_title('bold-title', fontweight=600) @image_comparison(['bold_font_output_with_none_fonttype.svg']) @@ -84,7 +85,8 @@ def test_bold_font_output_with_none_fonttype(): ax.plot(np.arange(10), np.arange(10)) ax.set_xlabel('nonbold-xlabel') ax.set_ylabel('bold-ylabel', fontweight='bold') - ax.set_title('bold-title', fontweight='bold') + # set weight as integer to assert it's handled properly + ax.set_title('bold-title', fontweight=600) @check_figures_equal(extensions=['svg'], tol=20) From 750a5fc94a1b7b750a29545fe4cb65c812b9e87f Mon Sep 17 00:00:00 2001 From: Steve Berardi Date: Wed, 14 Jan 2026 05:24:08 -0800 Subject: [PATCH 4/6] docstring --- lib/matplotlib/font_manager.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py index f85b08ffa8ff..d6365cb7f79b 100644 --- a/lib/matplotlib/font_manager.py +++ b/lib/matplotlib/font_manager.py @@ -747,7 +747,10 @@ def get_variant(self): def get_weight(self): """ - Return the font weight as an integer in the range 0-1000. + Get the font weight. Options are: A numeric value in the + range 0-1000 or one of 'light', 'normal', 'regular', 'book', + 'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold', + 'heavy', 'extra bold', 'black' """ return self._weight From ff7fe8f13162eb12ba4d9fd3ea33c4b5d96d2152 Mon Sep 17 00:00:00 2001 From: Steve Berardi <6608085+steveberardi@users.noreply.github.com> Date: Wed, 14 Jan 2026 05:42:44 -0800 Subject: [PATCH 5/6] Update lib/matplotlib/backends/backend_svg.py Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> --- lib/matplotlib/backends/backend_svg.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/backends/backend_svg.py b/lib/matplotlib/backends/backend_svg.py index 6b74363ff24f..c1f824007a56 100644 --- a/lib/matplotlib/backends/backend_svg.py +++ b/lib/matplotlib/backends/backend_svg.py @@ -1135,6 +1135,7 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None): if prop.get_variant() != 'normal': font_style['font-variant'] = prop.get_variant() weight = prop.get_weight() + weight = fm.weight_dict.get(weight, weight) # convert to int if weight != 400: font_style['font-weight'] = f'{weight}' From 29efd326b42bb80eb48d84f8cf9304654f4700aa Mon Sep 17 00:00:00 2001 From: Steve Berardi Date: Wed, 14 Jan 2026 06:15:23 -0800 Subject: [PATCH 6/6] revert --- lib/matplotlib/font_manager.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py index d6365cb7f79b..98361eaa01e8 100644 --- a/lib/matplotlib/font_manager.py +++ b/lib/matplotlib/font_manager.py @@ -23,6 +23,7 @@ # - font size is incomplete # - default font algorithm needs improvement and testing # - setWeights function needs improvement +# - 'light' is an invalid weight value, remove it. from __future__ import annotations