e.g. when I want to set font in
matplotlib.rc('font', **font)
Thanks.
e.g. when I want to set font in
matplotlib.rc('font', **font)
Thanks.
import matplotlib.font_manager
matplotlib.font_manager.findSystemFonts(fontpaths=None, fontext='ttf')
Check this for other options.
To get a (readable) list of fonts available to matplotlib:
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
The documentation recommends get_fontconfig_fonts():
This is an easy way to grab all of the fonts the user wants to be made available to applications, without needing knowing where all of them reside.
Note that you can get the (inverse) name to font lookup easily by using the FontProperties class:
font = matplotlib.font_manager.FontProperties(family='TeX Gyre Heros')
file = matplotlib.font_manager.findfont(font)
findfont is robust as it returns a default font if it can't find matching properties.
Per this blog post, this code will get you fonts available and samples:
import matplotlib.font_manager
from IPython.core.display import HTML
def make_html(fontname):
return "<p>{font}: <span style='font-family:{font}; font-size: 24px;'>{font}</p>".format(font=fontname)
code = "\n".join([make_html(font) for font in sorted(set([f.name for f in matplotlib.font_manager.fontManager.ttflist]))])
HTML("<div style='column-count: 2;'>{}</div>".format(code))
For example:
The accepted answer provides only a list of paths to fonts on your machine, but not the font name that you can pass to rcParams. @Alodi's answer addresses this point, but is outdated.
In Python 3.8.8 with Matplotlib 3.3.4, you can use the following:
import matplotlib.font_manager
fpaths = matplotlib.font_manager.findSystemFonts()
for i in fpaths:
f = matplotlib.font_manager.get_font(i)
print(f.family_name)
It prints a list of font names:
Padauk Book
Laksaman
Waree
Umpush
Latin Modern Roman Demi
Tlwg Mono
Gubbi
...