首页 > 解决方案 > 如何以编程方式保存 Spyder Plots 面板中显示的图像?

问题描述

我最近尝试使用pyplot.savefig()如下命令(从 matplotlib 导入)将图像保存在 Spyder 中,但它不起作用:

例如代码:

filename = 'myImage.png'

#images contain the image shown in the Spyder Plots pane
pyplot.imshow(images)

pyplot.savefig(filename)

我知道绘图窗格有一个保存按钮,但我想以编程方式保存图像(使用 Python)。

请指教。

谢谢!

标签: pythonimagematplotlibspyder

解决方案


用于plt.imsave()保存图像。这是代码:

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread('test.png')
plt.imshow(img)
plt.imsave("myImage.png", img)
plt.show()

推荐阅读