I am trying to set the font of a matplotlib plot to Times New Roman. I have tried:
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = 'Times New Roman'
I believe this is the correct way to set the font, but I keep getting this error that the found is not found:
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/font_manager.py:1238: UserWarning: findfont: Font family ['Times New Roman'] not found. Falling back to DejaVu Sans.
After some searching, I verified that I have the font downloaded. I tried opening a python shell and checking the contents of rcParams myself. Among a bunch of other font parameters, I curiously got a list of fonts in font.serif
that contains Times New Roman.
'font.serif': ['DejaVu Serif', 'Bitstream Vera Serif', 'Computer Modern Roman', 'New Century Schoolbook', 'Century Schoolbook L', 'Utopia', 'ITC Bookman', 'Bookman', 'Nimbus Roman No9 L', 'Times New Roman', 'Times', 'Palatino', 'Charter', 'serif'],
However, font.family
only contained one item: sans-serif
, when the matplotlib documentation states that there should be five values inside font.family
. Has anybody run into this error before? How did you fix it?
font.family
being set tosans-serif
is correct (as is also seen from the link you share). It can be one of five different values. – ImportanceOfBeingErnest