如何在matplotlib中获取字体系列(或字体名称)列表

2024-04-20 01:46:22 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在matplotlib中获取字体系列(或字体名称)列表。

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

借助这段代码,我只能得到字体目录。 如何获取字体名列表

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

提前谢谢。


Tags: 代码import目录名称none列表matplotlib字体
1条回答
网友
1楼 · 发布于 2024-04-20 01:46:22

尝试以下操作:

>>> 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', ...]

相关问题 更多 >