我想在matplotlib中使用替代字体。通过使用font_manager,我可以让诸如xlabel,ylabel或title之类的东西工作,但我无法弄清楚如何更改行标签的字体。
我选择了"Phosphate.ttc"字体,因为它很容易被发现。
import matplotlib.font_manager as fm
import matplotlib.pyplot as plt
def lineChart():
my_font = fm.FontProperties(fname='/Library/Fonts/Phosphate.ttc')
day = ('1','2','3')
line1 = (10,20,30)
line2 = (30,20,10)
fig, ax = plt.subplots()
ax.plot(day, line1, label='this goes to default font')
ax.plot(day, line2, label='this is default font too')
ax.legend(loc='upper center')
plt.title('title display correct', fontproperties=my_font)
plt.xlabel('xlabel display correct', fontproperties=my_font)
plt.ylabel('ylabel display correct', fontproperties=my_font)
plt.savefig("font_test.png")
if __name__ == '__main__':
lineChart()
有没有一种全局设置备用字体的方法?(不需要将其安装到 matplotlib 模块路径中)
或者设置行标签以使用备用字体?
操作系统:OSX
Python 版本:3.6.4
matplotlib 版本:2.1.1
谢谢