Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug]: FontManager.addfont doesn't accept pathlib.Path of TTF font #22582

Closed
Labels
Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesGood first issueOpen a pull request against these issues if there are no active ones!status: has patchpatch suggested, PR still neededtopic: text/fonts
Milestone
@twm

Description

@twm

Bug summary

TheFontManager.addfont() method is documented as accepting a path-like, but if a path-like for a .ttf font file is passed it raisesTypeError

Code for reproduction

frompathlibimportPathfrommatplotlibimportget_data_path,__version__frommatplotlib.font_managerimportfontManagerpath=Path(get_data_path())/"fonts"/"ttf"/"cmr10.ttf"print("matplotlib",__version__)fontManager.addfont(str(path))# Worksprint("str ok")fontManager.addfont(path)# TypeErrorprint("path ok")

Actual outcome

matplotlib 3.5.1str okTraceback (most recent call last):  File "/home/twm/dev/roofs/repro.py", line 10, in <module>    fontManager.addfont(path)  # TypeError  File "/home/twm/dev/roofs/venv/lib/python3.9/site-packages/matplotlib/font_manager.py", line 1092, in addfont    font = ft2font.FT2Font(path)TypeError: First argument must be a path or binary-mode file object

Expected outcome

matplotlib 3.5.1str okpath ok

Additional information

It looks like the simplest fix would be to convert path-likes tostr sinceFT2Font is implemented in C++.

Operating system

Ubuntu 20.04

Matplotlib Version

3.5.1

Matplotlib Backend

TkAgg

Python version

3.9.5

Jupyter version

N/A

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesGood first issueOpen a pull request against these issues if there are no active ones!status: has patchpatch suggested, PR still neededtopic: text/fonts

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp