This has been asked before but I havent found any working solution for me. I have been trying to figure out how to change default font in Matplotlib plot to Lato.
There are several posts/threads out there, e.g. 1, 2, 3. With these posts, I tried building up as following. Firstly, all fonts from my computer are added to font manager, like suggested in example 2.
from matplotlib import font_manager
font_dirs = [r"C:\Windows\Fonts"]
font_files = font_manager.findSystemFonts(fontpaths=font_dirs)
for font_file in font_files:
font_manager.fontManager.addfont(font_file)
result = font_manager.findfont("Lato")
print(result)
Output of print is --> C:\Windows\Fonts\Lato-Regular.ttf
Thus, Lato is detected by Font Manager. In the next step, I tried
import matplotlib as mpl
mpl.rcParams['font.family'] = 'Lato-Regular'
mpl.rcParams['font.sans-serif'] = 'Lato-Regular'
import matplotlib.pyplot as plt
plt.plot(range(0,50,10))
plt.title('Font test', size=32)
plt.show()
plt.savefig('f1.png')
Now code runs flawlessly, without any "DeJaVou" error. But font is still the default font and not Lato.
What am I doing wrong? Any help is appreciated ! Thanks.