代码
py
obj = "accu"
for (epoch,lr) in config:
with open('data/epoch_{}_lr_{}_Adam.pkl'.format(epoch,lr),'rb') as f:
data = pickle.load(f)
plt.plot(range(1,epoch+1),data[obj],label=f'lr={lr}')
plt.title(obj+"-epoch")
plt.xlabel("epoch")
plt.grid(axis='x',linestyle='-.',linewidth=1,color='skyblue')
plt.grid(axis='y',linestyle='-.',linewidth=1,color='skyblue')
plt.xticks(np.linspace(0,20,21,endpoint=True))
plt.yticks(np.linspace(60,100,21,endpoint=True))
plt.ylabel(obj)
plt.legend()
plt.savefig(f"data/{obj}_graph.png")
plt.close()
- np.linspace获取间隔为小数的序列,21代表间隔点的数目;
- plt.xticks设置横纵坐标的间隔;
- pplt.grid()绘制网格线,进行相应设置。