在使用pyplot函数的时候, xlabel 和 ylabel 以及标题都不能显示中文,且控制台有报错,原来是pyplot默认是不支持中文的
通过以下方法设置
1. 通过plot.rcParams修改字体实现
- font.family:字体名
plt.rcParams["font.family"] = ["sans-serif"]
plt.rcParams["font.sans-serif"] = ['SimHei']
2. 使用中文的时候,增加属性fontproperties
plt.title("损失函数的值", fontproperties="SimHei")
plt.xlabel("训练次数", fontproperties="SimHei")
plt.ylabel("损失函数", fontproperties="SimHei")