How to get a list of all the fonts currently available for Matplotlib?


e.g. when I want to set font in

matplotlib.rc('font', **font)
Asked By: nye17



import matplotlib.font_manager
matplotlib.font_manager.findSystemFonts(fontpaths=None, fontext='ttf')

Check this for other options.

Answered By: imsc

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

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.

Answered By: alodi

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([ for f in matplotlib.font_manager.fontManager.ttflist]))])

HTML("<div style='column-count: 2;'>{}</div>".format(code))

For example:

enter image description here

Answered By: Max Ghenis

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)

It prints a list of font names:

Padauk Book
Latin Modern Roman Demi
Tlwg Mono
Answered By: Max

New in matplotlib 3.6.0

There is now a helper method get_font_names() to list all available fonts:

from matplotlib import font_manager

Note that the resulting list won’t be alphabetical. That’s fine if you’re just checking something programmatically, but if you’re checking visually, sort alphabetically for easier scanning:


# ['Advent Pro',
#  'Anonymous Pro',
#  ...
#  'DejaVu Sans',
#  'DejaVu Sans Mono',
#  'DejaVu Serif',
#  ...
#  'Noto Mono',
#  'Noto Sans',
#  'Noto Serif',
#  ...
#  'Roboto',
#  'Roboto Flex',
#  'Roboto Mono',
#  'Roboto Serif',
#  ...
#  'TeX Gyre Adventor',
#  'TeX Gyre Bonum',
#  'TeX Gyre Chorus',
#  'TeX Gyre Cursor',
#  'TeX Gyre Heros',
#  'TeX Gyre Pagella',
#  'TeX Gyre Schola',
#  'TeX Gyre Termes',
#  ...
#  'Ubuntu',
#  'Ubuntu Mono']
Answered By: tdy
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.