Reputation: 434
First things first: Windows 10, python 3.8, matplotlib 3. (I've had the same problem with Anaconda python 3.7)
I've installed Helvetica from this source in my C:\Windows\Fonts folder. I've tried running this script and get the following error:
import matplotlib.pyplot as plt
from matplotlib import rcParams
rcParams['font.family'] = ['Helvetica Normal']
fig,ax = plt.subplots()
plt.show()
findfont: Font family ['Helvetica Normal'] not found. Falling back to DejaVu Sans.
I've tried Helvetica and Helvetica Standard before that. It works with Trebuchet, which, as far as I know, is only installed in my system fonts and not any of the matplotlib font folders.
I tried a lot of solutions, but I just don't know how to specify the font for matplotlib globally. I've tried every solution I found on github, stackoverflow etc. I've had this problem for over a year now but I can't find a suitable solution to this.
Upvotes: 2
Views: 3801
Reputation: 339290
C:\Windows\Fonts\Helvetica 400.ttf
)Run
fp = matplotlib.font_manager.FontProperties(fname=r"C:\Windows\Fonts\Helvetica 400.ttf")
print(fp.get_name())
to get the name of the font printed. It would be Helvetica
in this case.
Rebuild the font cache. This could be done by deleting the fontlist-vXXX.json
(where XXX = 310
for version 3.1.0) file from the matplotlib folder. Or by running matplotlib.font_manager._rebuild()
via code.
plt.rcParams['font.family'] = ['Helvetica']
Upvotes: 3