Saturday, 4 January 2020

Unable to use custom fonts in matplotlib

I'm having trouble getting a custom font to work with Matplotlib (version 3.1.1) on Python 3.7.3 on Windows. The standard way using

import matplotlib as mpl
mpl.rcParams['font.family'] = 'sans-serif'
mpl.rcParams['font.sans-serif'] = [FONTNAME] 

works fine for a range of fonts preinstalled on the system. I recently manually installed the Lato family of fonts. However, when I use 'Lato' as FONTNAME, Matplotlib defaults back to Deja Vu Sans and doesn't even throw any errors. I also rebuilt the font cache using

mpl.font_manager._rebuild()

Several fonts named 'Lato' now appear when I run

mpl.font_manager.fontManager.ttflist

such as

 <Font 'Lato' (Lato-Semibold.ttf) normal normal semibold normal>,
 <Font 'Lato' (Lato-Thin.ttf) normal normal 400 normal>,
...

Yet the plots still look like they use Deja Vu Sans. I've looked all over but couldn't find a solution to this issue.



from Unable to use custom fonts in matplotlib

No comments:

Post a Comment