python画图中文为宋体,英文为Times New Roman
参考链接如下:https://blog.csdn.net/qq_41821678/article/details/105804345
import numpy as npimport matplotlib.pyplot as plt
from matplotlib import rcParams
config = {
"font.family":'serif',
"font.size": 7.5,
"mathtext.fontset": 'stix',
"font.serif": ['SimSun'],
}
rcParams.update(config)
traindata = np.genfromtxt("./1.txt", dtype=np.float32)[:,1]
testdata = np.genfromtxt("./2.txt", dtype=np.float32)[:, 1]
plt.rcParams['font.sans-serif']=['SimHei'] #用来显示中文标签
plt.figure(figsize=(19.2, 10.8))
# plt.title('损失函数衰减曲线',fontsize=20)
# # plt.xlabel("迭代轮数(epochs)",fontsize=20)
# # plt.ylabel("损失函数值",fontsize=20)
plt.title('Loss Curve 厉害了',fontsize=25)
plt.xlabel("Epochs",fontsize=25)
plt.ylabel("Loss Values",fontsize=25)
plt.plot(traindata,label="train-loss")
plt.plot(testdata, label="val-loss")
plt.tick_params(labelsize=20) #调整坐标轴刻度的字体大小
plt.legend(fontsize=18) #参数调整train-loss与val-loss字体的大小
plt.savefig("./pan5.png",bbox_inches='tight')
plt.show()
以上是 python画图中文为宋体,英文为Times New Roman 的全部内容, 来源链接: utcz.com/z/388674.html