Skip to content

Commit a59d1d2

Browse files
steveberardimeeseeksmachine
authored andcommitted
Backport PR matplotlib#30960: SVG backend - handle font weight as integer
1 parent 2f0ea8b commit a59d1d2

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

lib/matplotlib/backends/backend_svg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,8 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None):
11321132
font_style['font-style'] = prop.get_style()
11331133
if prop.get_variant() != 'normal':
11341134
font_style['font-variant'] = prop.get_variant()
1135-
weight = fm.weight_dict[prop.get_weight()]
1135+
weight = prop.get_weight()
1136+
weight = fm.weight_dict.get(weight, weight) # convert to int
11361137
if weight != 400:
11371138
font_style['font-weight'] = f'{weight}'
11381139

lib/matplotlib/font_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ def get_variant(self):
744744

745745
def get_weight(self):
746746
"""
747-
Set the font weight. Options are: A numeric value in the
747+
Get the font weight. Options are: A numeric value in the
748748
range 0-1000 or one of 'light', 'normal', 'regular', 'book',
749749
'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold',
750750
'heavy', 'extra bold', 'black'

lib/matplotlib/tests/test_backend_svg.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ def test_bold_font_output():
7373
ax.plot(np.arange(10), np.arange(10))
7474
ax.set_xlabel('nonbold-xlabel')
7575
ax.set_ylabel('bold-ylabel', fontweight='bold')
76-
ax.set_title('bold-title', fontweight='bold')
76+
# set weight as integer to assert it's handled properly
77+
ax.set_title('bold-title', fontweight=600)
7778

7879

7980
@image_comparison(['bold_font_output_with_none_fonttype.svg'])
@@ -83,7 +84,8 @@ def test_bold_font_output_with_none_fonttype():
8384
ax.plot(np.arange(10), np.arange(10))
8485
ax.set_xlabel('nonbold-xlabel')
8586
ax.set_ylabel('bold-ylabel', fontweight='bold')
86-
ax.set_title('bold-title', fontweight='bold')
87+
# set weight as integer to assert it's handled properly
88+
ax.set_title('bold-title', fontweight=600)
8789

8890

8991
@check_figures_equal(tol=20)

0 commit comments

Comments
 (0)