首页 > 解决方案 > 在 Python 3 中使用 matplotlib.font_manage 获取所有字体样式

问题描述

请问,
是否可以打印出每种列出的字体具有的每种样式?所以我知道例如 Arial 有 Bold、Regular、Italic 等等。谢谢!或者你会推荐一些其他的工具来做到这一点?我在 Windows 7 上。

import matplotlib.font_manager
#help(matplotlib.font_manager)
fonts = [f.name for f in matplotlib.font_manager.fontManager.ttflist]
print(len(fonts))
for i in fonts:
    print(i)

标签: pythonpython-3.xfonts

解决方案


是的。

和方法让您get_style()探索get_variant()一些字体空间。

您可能想要迭代几种可能性,调用score_style()以确定样式是否可用。或者只是迭代并查看 的结果findfont(),让它计算哪些样式在本地可用。如果您发布迭代代码及其结果,我们可能会提供额外的字体提示。


推荐阅读