使用系统:win-10,导致报错的编码如下。错误之处在 “ # x ”。 错误原因:使用了mac系统的字体库路径"/System/Library/Fonts/PingFang.ttc"。 fontpropert = my_font 的fontpropert 应是fontproperties
from matplotlib import pyplot as plt
from matplotlib import font_manager
my_font = font_manager.FontProperties(fname="/System/Library/Fonts/PingFang.ttc") # x
y = [1,4,8,1,3,4,3,2,3,6]
x = range(11,21)
plt.plot(x, y)
_xtick_labels = ["{}岁".format(i) for i in x]
plt.xticks(x, _xtick_labels, fontpropert = my_font) # X
plt.show()
# 第一处编码的报错信息: No such file or directory: '/System/Library/Fonts/PingFang.ttc'
# 第二处编码的报错信息:AttributeError: Unknown property fontpropert
正确编码如下:
from matplotlib import pyplot as plt
from matplotlib import font_manager
# my_font = font_manager.FontProperties(fname=