【问题标题】:How to save an image created from a numpy array?如何保存从 numpy 数组创建的图像?
【发布时间】:2017-03-20 12:54:46
【问题描述】:

我想使用 plt.savefig() 保存从 numpy 数组创建的图像,但它失败了。我的图像是空白的。我的代码如下。

import matplotlib.pyplot as plt
import numpy as np

array = np.arange(10000).reshape((100,100))
plt.savefig('test.png', dpi = 300)
plt.imshow(array)

以及如何为我的图像添加颜色条?非常感谢你。 就像下图一样。

【问题讨论】:

标签: python arrays image save


【解决方案1】:
fig = plt.figure(figsize = (12,12))

data = np.arange(10000).reshape((100,100))
plt.subplot(111)
plt.imshow(data,interpolation='nearest', cmap='bone', origin='lower')
plt.colorbar(shrink=.92)

plt.savefig('imshow_ex.png', dpi=100)
plt.show()

上面的代码可以解决我的问题。谢谢。

【讨论】:

    猜你喜欢
    • 2018-10-16
    • 1970-01-01
    • 2021-02-20
    • 2017-12-28
    • 2016-03-23
    • 2020-09-10
    • 1970-01-01
    • 2021-04-21
    相关资源
    最近更新 更多