python - 如何以编程方式保存 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)。
请指教。
谢谢!
解决方案
用于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()
推荐阅读
- scala - Scala宏:从类类型中获取伴随对象
- java - 从java运行linux命令
- apache-spark - Spark:映射组和展平数组
- pandas - 如何使用 Pandas 将数据框行数据转换为列
- swift - Swift 中的 int 到 int
- excel - 使用 VBA 添加新行时如何在单元格中添加特定值
- python-3.x - 有没有办法用 '#' 替换从索引 0 到索引 -4 的字符串中的字符(即除了最后 4 个字符之外的所有字符)
- node.js - 如何防止我的 App Engine 应用出现“appspot.com”?
- javascript - 跨域请求块 Node.js
- ansible - 将文件内容转换为 ansible 或 jinja2 中的单行,其中 \n 字符替换原始换行符