首页 > 解决方案 > 如何保存两个单独的图

问题描述

对于我的深度学习项目,我试图将每个 epoch 的训练准确度和验证准确度保存为图表,以及类似的训练损失和验证损失。

第一个图正确保存,但第二个图包括相同网格线(图)中的两个图。

"""#Plot Training & Test Accuracy"""

epochs_list = [i for i in range(epochs)]
plt.plot(epochs_list, acc, label='Training accuracy')
plt.plot(epochs_list, val_acc, label='Validation accuracy')
plt.title('Model Accuracy')
plt.ylabel('Accuracy')
plt.xlabel('epochs')
plt.legend()
plt.show()
plt.savefig("V5_Full_Accuracy.png")

print("")



"""#Plot Training & Test Loss"""
plt.plot(epochs_list, loss, label='Training loss')
plt.plot(epochs_list, val_loss, label='Validation loss')
plt.title('Model Loss')
plt.ylabel('Loss')
plt.xlabel('epochs')
plt.legend()
plt.show()
plt.savefig(V5_Full_Loss.png)

标签: pythonmatplotlib

解决方案


你需要做plt.show() 之后 plt.savefig()

plt.savefig("V5_Full_Accuracy.png")
plt.show()

第二个情节也一样。


推荐阅读