Repository: matplotlib/matplotlib

Issue:
# SVG backend - handle font weight as integer

<!--
Thank you so much for your PR!  To help us review your contribution, please check
out the development guide https://matplotlib.org/devdocs/devel/index.html
-->

## PR summary

This fixes a small bug with handling integer font weights when rendering text in SVGs as elements vs paths (i.e. `plt.rcParams['svg.fonttype'] = 'none'`).

To reproduce:

```python

plt.rcParams['svg.fonttype'] = 'none'
fig, ax = plt.subplots()
ax.set_title('bold-title', fontweight=600)
```
Raises:
```
KeyError: 600
lib/matplotlib/backends/backend_svg.py:1138: KeyError
```

The problem is that the font [`weight_dict` is keyed on the string values](https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/font_manager.py#L82), but `get_weight` returns an integer.


## PR checklist
<!-- Please mark any checkboxes that do not apply to this PR as [N/A].-->

I couldn't find an open issue for this, but let me know if one exists already. This is also my first PR to matplotlib, so let me know if there's anything I missed in your contribution process. Appreciate any feedback! And, thanks so much for maintaining this library! It's the backbone of [Starplot](https://github.com/steveberardi/starplot), a sky mapping library I maintain.

- [ ] "closes #0000" is in the body of the PR description to [link the related issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
- [X] new and changed code is [tested](https://matplotlib.org/devdocs/devel/testing.html)
- [ ] *Plotting related* features are demonstrated in an [example](https://matplotlib.org/devdocs/devel/document.html#write-examples-and-tutorials)
- [ ] *New Features* and *API Changes* are noted with a [directive and release note](https://matplotlib.org/devdocs/devel/api_changes.html#announce-changes-deprecations-and-new-features)
- [ ] Documentation complies with [general](https://matplotlib.org/devdocs/devel/document.html#write-rest-pages) and [docstring](https://matplotlib.org/devdocs/devel/document.html#write-docstrings) guidelines

<!--We understand that PRs can sometimes be overwhelming, especially as the
reviews start coming in.  Please let us know if the reviews are unclear or
the recommended next step seems overly demanding, if you would like help in
addressing a reviewer's comments, or if you have been waiting too long to hear
back on your PR.-->


Implementation patch:
diff --git a/lib/matplotlib/backends/backend_svg.py b/lib/matplotlib/backends/backend_svg.py
index 2193dc6b6cdc..7789ec2cd882 100644
--- a/lib/matplotlib/backends/backend_svg.py
+++ b/lib/matplotlib/backends/backend_svg.py
@@ -1132,7 +1132,8 @@ 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()
+            weight = fm.weight_dict.get(weight, weight)  # convert to int
             if weight != 400:
                 font_style['font-weight'] = f'{weight}'
 
diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py
index 9aa8dccde444..a44d5bd76b9a 100644
--- a/lib/matplotlib/font_manager.py
+++ b/lib/matplotlib/font_manager.py
@@ -744,7 +744,7 @@ def get_variant(self):
 
     def get_weight(self):
         """
-        Set the font weight.  Options are: A numeric value in the
+        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'


Test patch:
diff --git a/lib/matplotlib/tests/test_backend_svg.py b/lib/matplotlib/tests/test_backend_svg.py
index 509136fe323e..0f9f5f19afb5 100644
--- a/lib/matplotlib/tests/test_backend_svg.py
+++ b/lib/matplotlib/tests/test_backend_svg.py
@@ -73,7 +73,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'])
@@ -83,7 +84,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(tol=20)