Skip to content

FontProperties fail to roundtrip from their str #14977

Closed

Description

@anntzer

Bug report

Bug summary

FontProperties has a __str__ that appears to be intended to allow roundtripping (see use of get_fontconfig_pattern/parse_fontconfig_pattern), but after fp = FontProperties(); one has FontProperties(str(fp)) != fp.

Code for reproduction

from matplotlib.font_manager import FontProperties, findfont
from matplotlib import style; style.use("seaborn")

fp = FontProperties()
print(fp)
print(findfont(fp))
fp_str_roundtrip = FontProperties(str(fp))
print(fp_str_roundtrip)
print(findfont(fp_str_roundtrip))

(setting the style to (matplotlib's version of) seaborn has the side-effect of changing the default sans-serif font from dejavusans to arial, which leads to the difference in the result of findfont -- otherwise, the default sans-serif font is also dejavusans and both calls to findfont return it).

Actual outcome

:family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0
/usr/share/fonts/TTF/arial.ttf
:family=:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0
findfont: Font family [''] not found. Falling back to DejaVu Sans.
/home/antony/src/extern/matplotlib/lib/matplotlib/mpl-data/fonts/ttf/DejaVuSans.ttf

Expected outcome

Proper roundtripping.

Matplotlib version

  • Operating system: linux
  • Matplotlib version: master
  • Matplotlib backend (print(matplotlib.get_backend())): any
  • Python version: 37
  • Jupyter version (if applicable):
  • Other libraries:

Activity

  1. github-actions commented on Jun 26, 2023

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  2. added
    keepItems to be ignored by the “Stale” Github Action
    and removed
    status: inactiveMarked by the “Stale” Github Action
    on Jun 26, 2023
  3. QuLogic commented on Jul 1, 2025

    @QuLogic
    Member

    It seems like this is fixed; I get (after changing styles to seaborn-v0_8):

    $ python ../mpl-tests/issue14977.py
    sans\-serif:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0
    /usr/share/fonts/liberation-sans-fonts/LiberationSans-Regular.ttf
    sans\-serif:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0
    /usr/share/fonts/liberation-sans-fonts/LiberationSans-Regular.ttf
    

    which looks consistent to me.

  4. removed
    keepItems to be ignored by the “Stale” Github Action
    on Jul 1, 2025
  5. anntzer commented on Jul 1, 2025

    @anntzer
    ContributorAuthor

    Likely this was fixed by #15601.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions