无论我发送1还是0数组,Python matplotlib imshow总是给我白色

曼普雷特·辛格·布林德
import matplotlib.pyplot as plt
import numpy as np
_im1 = np.array([
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1]
]).astype(np.uint8)

_im2 = np.array([
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0]
]).astype(np.uint8)


fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 8))

ax1.set_title('1s')
ax1.imshow(_im1 , cmap='binary')

ax2.set_title('Os')
ax2.imshow(_im2, cmap='binary')

plt.tight_layout()
plt.subplots_adjust(top=1)
plt.show()
plt.clf()

我将两个图像都变成白色。我尝试使用cmap ='grey'然后都显示为黑色我正在使用它有参考:将图像数组乘以标量后使用plt.imshow获取黑色图

柯蒂斯·史特鲁特克
ax1.set_title('1s')
ax1.imshow(_im1, cmap='binary', vmin=0, vmax=1)

ax2.set_title('Os')
ax2.imshow(_im2, cmap='binary', vmin=0, vmax=1)

编辑:更新以满足评论。cmap='gray'使用vmax / vmin也可以

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章