Skip to content

SVG backend - handle font weight as integer#30960

Merged
story645 merged 6 commits intomatplotlib:mainfrom
steveberardi:svg-backend-font-weight
Jan 14, 2026
Merged

SVG backend - handle font weight as integer#30960
story645 merged 6 commits intomatplotlib:mainfrom
steveberardi:svg-backend-font-weight

Conversation

@steveberardi
Copy link
Contributor

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:

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, but get_weight returns an integer.

PR checklist

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, a sky mapping library I maintain.

story645 added a commit to story645/starplot that referenced this pull request Jan 13, 2026
Hi, 
Since you mentioned Starplot in matplotlib/matplotlib#30960, figured you might be interested in identifying the project as an mpl downstream library on PyPI via the trove classifier. Also please consider your very cool library to https://matplotlib.org/thirdpartypackages/
@story645
Copy link
Member

Thanks for the PR! What happens if someone passes in a string fontweight (for example they're saving to multiple filetypes)?

steveberardi and others added 2 commits January 14, 2026 05:42
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
@story645 story645 added this to the v3.10.9 milestone Jan 14, 2026
@story645 story645 merged commit 3a1df7d into matplotlib:main Jan 14, 2026
40 checks passed
@story645
Copy link
Member

Thanks for the bug fix!

meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jan 14, 2026
timhoffm added a commit that referenced this pull request Jan 14, 2026
…960-on-v3.10.x

Backport PR #30960 on branch v3.10.x (SVG backend - handle font weight as integer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants