python - 将 Rainbow 矩阵转换为 RBG 并保存为 PNG
问题描述
我正在关注本教程:https : //pyts.readthedocs.io/en/latest/auto_examples/plot_gaf.html 以生成 GADF 和 GASF 矩阵。
一切正常。我只需要将其中包含的结果保存为png,X_gasf[0]
但我不知道该怎么做。
我已经尝试过了:
fig = plt.imshow(X_gadf[0], cmap='rainbow', aspect='equal')
fig.axes.get_xaxis().set_visible(False)
fig.axes.get_yaxis().set_visible(False)
plt.axis('off')
plt.savefig(GADF_path + filename, pad_inches=0, bbox_inches='tight')
这段代码有效,但仍然给我图像周围的白色边框(对我来说,没有任何白色边框非常重要)。
我也试过这个:
# Test 1
matplotlib.image.imsave(filename, X_gadf[0])
# Test 2
im = Image.fromarray(X_gadf[0], mode='HSV')
im.save(GADF_path + filename)
# Test 3
cv2.imread(X_gadf[0])
imsave(filename, X_gadf[0])
但这些解决方案都不起作用。这似乎X_gadf[0]
是一种我无法管理的奇怪图像。
有任何想法吗?
解决方案
你试过这个吗?
matplotlib.image.imsave(filename, X_gasf[0], cmap='rainbow')
查看文档,您似乎忘记了cmap='rainbow'
推荐阅读
- javascript - 在箭头函数执行期间过滤数组
- reactjs - react 说 Error: Invalid hook call when I try to use material makestyles
- sql - 使用数据库链接时在多个条件下进行内连接
- android - 保存片段状态导航组件JAVA
- python - Python Selenium - 数据不可见;没有错误
- javascript - 画布上下文上的多个填充():rgba透明颜色改变
- excel - Excel 动态数组 - 可能的错误?
- javascript - 不随页面刷新的计数器
- swiftui - SwiftUI 从 UITextField 中关闭键盘
- image - 如何将图像添加到 Go 中的特定文件夹中?收到类似错误:`%!(EXTRA *fs.PathError=open /photos: read-only file system)`