So I've tried pretty much everything I could find on stackoverflow (and anywhere else google would lead me) ; and I just can't change the god damn font !
Here comes the non-exhaustive list of what I've tried so far :
Trying as suggested in this question :
import matplotlib.pyplot as plt
csfont = {'fontname':'Times New Roman'}
x = [1,2,3]
y = x
plt.plot(x,y)
plt.title('Please be Times >__<',**csfont)
plt.show()
gives me this error log :
>>> (executing file "<tmp 1>")
Note on using QApplication.exec_():
The GUI event loop is already running in the pyzo kernel, and exec_()
does not block. In most cases your app should run fine without the need
for modifications. For clarity, this is what the pyzo kernel does:
- Prevent deletion of objects in the local scope of functions leading to exec_()
- Prevent system exit right after the exec_() call
/home/antoine/miniconda3/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['Times New Roman'] not found. Falling back to DejaVu Sans
(prop.get_family(), self.defaultFamily[fontext]))
>>>
This answer didn't quite help me either :
import matplotlib.pyplot as plt
plt.rcParams["font.family"] = "Times New Roman"
x = [1,2,3]
y = x
plt.plot(x,y)
plt.title('Please be Times >__<',**csfont)
plt.show()
There is no error shown ; but this is not Times ...
It's also a bit wierd to me that the first attempt gives that error log, as doing what this answer suggests shows that Times New Roman is indeed a font I should be able to use :
>>> set([f.name for f in matplotlib.font_manager.fontManager.afmlist])
{'Courier', 'Times', 'URW Bookman L', 'Nimbus Mono L', 'ITC Bookman', 'ZapfDingbats', 'Century Schoolbook L', 'New Century Schoolbook', 'Helvetica', 'Standard Symbols L', 'Utopia', 'Palatino', 'URW Gothic L', 'Courier 10 Pitch', 'Symbol', 'Computer Modern', 'Bitstream Charter', 'ITC Avant Garde Gothic', 'Nimbus Roman No9 L', 'ITC Zapf Chancery', 'ITC Zapf Dingbats', 'URW Chancery L', 'Nimbus Sans L', 'Dingbats', 'URW Palladio L'}
So ... What else can I try ?
In order to see which fonts are available, you should use this method:
import matplotlib.font_manager
flist = matplotlib.font_manager.get_fontconfig_fonts()
names = [matplotlib.font_manager.FontProperties(fname=fname).get_name() for fname in flist]
print(names)
Then see if "Times New Roman" is there or not.
if "Times New Roman" in names:
print("Yes")
else:
print("font not available")
If it isn't, you can't use it. If it is, the following will work as expected.
import matplotlib.pyplot as plt
plt.rcParams["font.family"] = "Times New Roman"
plt.plot([1,2,3])
plt.title('Please be Times New Roman')
plt.show()
Note that you may specify several fonts. The first that actually is available will be chosen. Adding "serif"
last in the list at least makes sure to fall back to a serif font if none of the others is present.
plt.rcParams["font.family"] = "Gulasch", "Times", "Times New Roman", "serif"