Closed
Description
Bug summary
The FontManager.addfont()
method is documented as accepting a path-like, but if a path-like for a .ttf font file is passed it raises TypeError
Code for reproduction
from pathlib import Path
from matplotlib import get_data_path, __version__
from matplotlib.font_manager import fontManager
path = Path(get_data_path()) / "fonts" / "ttf" / "cmr10.ttf"
print("matplotlib", __version__)
fontManager.addfont(str(path)) # Works
print("str ok")
fontManager.addfont(path) # TypeError
print("path ok")
Actual outcome
matplotlib 3.5.1
str ok
Traceback (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.1
str ok
path ok
Additional information
It looks like the simplest
6351
fix would be to convert path-likes to str
since FT2Font
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