Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Closed
Labels
Milestone
Description
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