Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3a1df7d

Browse files
SVG backend - handle font weight as integer (#30960)
* weight is int * comments * test * docstring * Update lib/matplotlib/backends/backend_svg.py Co-authored-by: Tim Hoffmann <[email protected]> * revert --------- Co-authored-by: Tim Hoffmann <[email protected]>
1 parent 77b5114 commit 3a1df7d

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

lib/matplotlib/backends/backend_svg.py

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

lib/matplotlib/font_manager.py

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

749749
def get_weight(self):
750750
"""
751-
Set the font weight. Options are: A numeric value in the
751+
Get the font weight. Options are: A numeric value in the
752752
range 0-1000 or one of 'light', 'normal', 'regular', 'book',
753753
'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold',
754754
'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
@@ -74,7 +74,8 @@ def test_bold_font_output():
7474
ax.plot(np.arange(10), np.arange(10))
7575
ax.set_xlabel('nonbold-xlabel')
7676
ax.set_ylabel('bold-ylabel', fontweight='bold')
77-
ax.set_title('bold-title', fontweight='bold')
77+
# set weight as integer to assert it's handled properly
78+
ax.set_title('bold-title', fontweight=600)
7879

7980

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

8991

9092
@check_figures_equal(extensions=['svg'], tol=20)

0 commit comments

Comments
 (0)