【问题标题】:How do you save an image displayed in Spyder Plots panel programmatically?如何以编程方式保存 Spyder Plots 面板中显示的图像?
【发布时间】:2021-04-19 03:59:02
【问题描述】:

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

例如代码:

filename = 'myImage.png'

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

pyplot.savefig(filename)

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

请指教。

谢谢!

【问题讨论】:

    标签: python image matplotlib spyder


    【解决方案1】:

    使用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()
    

    【讨论】:

    • 谢谢,这对单张图像效果很好?但是现在我正在尝试使用 hstack/vstack 在 pyplot 中显示图像数组&这种方法只保存数组中的最后一张图像?有没有办法以编程方式将 pyplot 中显示的内容准确保存到单个图像文件中?谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-09
    • 2010-12-20
    • 1970-01-01
    • 2010-10-16
    • 1970-01-01
    相关资源
    最近更新 更多