16

How can i get list of font family(or Name of Font) in matplotlib.

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

With help of this code i can get only directory of font. How can i get list of Font-Name like

"Century Schoolbook L", "Ubuntu".... etc

Thanks in Advance.

falsetru
  • 357,413
  • 63
  • 732
  • 636
Parth Gajjar
  • 1,334
  • 3
  • 12
  • 35

1 Answers1

33

Try following:

>>> import matplotlib.font_manager
>>> [f.name for f in matplotlib.font_manager.fontManager.ttflist]
['cmb10', 'cmex10', 'STIXNonUnicode', 'STIXNonUnicode', 'STIXSizeThreeSym', 'STIXSizeTwoSym', 'cmtt10', 'STIXGeneral', 'STIXSizeThreeSym', 'STIXSizeFiveSym', 'STIXSizeOneSym', 'STIXGeneral', 'cmr10', 'STIXSizeTwoSym', ...]
>>> [f.name for f in matplotlib.font_manager.fontManager.afmlist]
['Helvetica', 'ITC Zapf Chancery', 'Palatino', 'Utopia', 'Helvetica', 'Helvetica', 'ITC Bookman', 'Courier', 'Helvetica', 'Times', 'Courier', 'Helvetica', 'Utopia', 'New Century Schoolbook', ...]
falsetru
  • 357,413
  • 63
  • 732
  • 636
  • 4
    It might render _a lot_ of duplicates, adding `set()` will give you the unique fonts ordered apathetically. So, `set([f.name for f in matplotlib.font_manager.fontManager.afmlist])` and `set([f.name for f in matplotlib.font_manager.fontManager.ttflist])` – Mart Van de Ven May 18 '15 at 16:23
  • 4
    @MartVandeVen, Thank you for your comment. FYI, in Python 2.7, set comprehension is also available. `{f.name for f in matplotlib.font_manager.fontManager.afmlist}`. Also you can use generator expression instead of list comprehension (to avoid creating intermediate list object). – falsetru May 19 '15 at 00:12