繁体   English   中英

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

[英]Python matplotlib imshow always give me white no matter if i send array of 1s or 0s

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 ='gray'然后两个显示为黑色我使用它有参考: 在图像数组乘以标量后用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)

编辑:更新以满足评论。 带有vmax / vmin的cmap='gray'也适用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM