import matplotlib.pyplot as plt
# 支持中文
plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
fig, ax1 = plt.subplots()
#ax2 = ax1.twinx()
# 按一定间隔显示实现方法
# ax2.plot(200 * np.arange(len(fig_accuracy1)), fig_accuracy1, 'r')
lns1 = ax1.plot(np.arange(1500), fig_accuracy1, 'r', label="学习率0.01")
lns2 = ax1.plot(np.arange(1500), fig_accuracy2, 'b', label="学习率0.0001")
lns3 = ax1.plot(np.arange(1500), fig_accuracy3, 'g', label="动态调整学习率")
ax1.set_xlabel('迭代次数')
ax1.set_ylabel('训练精度')
# ax2.set_ylabel('training accuracy')
# 合并图例
lns = lns1 + lns2+lns3
labels = ["学习率0.01","学习率0.0001","动态调整学习率"]
ax = plt.gca() # get current axis 获得坐标轴对象
# labels = [l.get_label() for l in lns]
plt.legend(lns, labels, loc=4)
plt.savefig("Accuracytest.png",dpi=500,bbox_inches = 'tight')#解决图片不清晰,不完整的问题
plt.show()
# =============================================================================
# 将npy格式的变量文件读取到csv格式文件并保存
# import numpy as np
# input_data = np.load(r"D:\course\02 论文\小论文\BearLSTM-master\BearLSTM-master\battery\fig_accuracy3.npy")
# print(input_data.shape)
# data = input_data.reshape(1,-1)
# print(data.shape)
# print(data)
# np.savetxt(r"D:\course\02 论文\小论文\BearLSTM-master\BearLSTM-master\battery\test3.csv",data,delimiter=',')
# =============================================================================
LSTM程序
最新推荐文章于 2024-07-25 10:37:06 发布