How can i get list of font family(or Name of Font) in matplotlib
Asked Answered
S

1

17

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.

Stratum answered 16/9, 2013 at 6:41 Comment(0)
B
34

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', ...]
Bergama answered 16/9, 2013 at 6:54 Comment(2)
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])Topcoat
@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).Bergama

© 2022 - 2024 — McMap. All rights reserved.