python - 如何保存两个单独的图
问题描述
对于我的深度学习项目,我试图将每个 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)
解决方案
你需要做plt.show()
之后 plt.savefig()
。
plt.savefig("V5_Full_Accuracy.png")
plt.show()
第二个情节也一样。
推荐阅读
- sapui5 - 验证输入框在表格行中被禁用 - SAP UI5
- c# - 依赖注入单例到瞬态
- c++ - 在不使用数据库的情况下在进程之间共享设置?
- python - 如何从用户那里获取输入以在字典中查找键并输出其值?
- angularjs - 如何在 AngularJs 中使用 UI-Route 在每个页面中设置动态元数据
- html - 如何在 Angular 中创建自定义下拉组件
- java - 位图而不是视图上的波纹动画
- python-3.x - 从网站python selenium中提取按钮链接文本
- react-native - 如何在打开使用 react-native fs 编写的文档时修复错误“无法打开文档,文件似乎已损坏”?
- windows - Docker:Hyper-V 在尝试访问计算机“主机”上的对象时遇到错误