小编kwi*_*ill的帖子

为什么matplotlib不使用我提供的.ttf字体?

我正在尝试在matplotlib中使用TTF字体; .ttf文件已下载并在我的机器上本地存在.我已按照本网站上的其他说明选择使用的字体font_manager; 但是,我生成的任何试图使用字体属性的文本仍然以默认的matplotlib字体显示.

我知道Python确实成功找到了字体文件,因为prop.get_name()类似的命令确实显示了我想要的字体的属性 - 但这不是我的图中出现的.有什么建议?

举个例子:

import matplotlib.pyplot as plt
import matplotlib.font_manager as fm

fig, ax = plt.subplots()

prop = fm.FontProperties(fname='/Users/smith/fonts/coolfont.ttf')
ax.set_title('Text in a cool font', fontproperties=prop, size=40)

fig.show()
Run Code Online (Sandbox Code Playgroud)

python fonts matplotlib

7
推荐指数
1
解决办法
3390
查看次数

标签 统计

fonts ×1

matplotlib ×1

python ×1