我正在尝试在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)