在 imshow-plot 上绘制单个像素的方法

Way to plot single pixels on imshow-plot

假设我在 imshow 中有如下内容:

b = np.array([[0,0,0,0,0,0,0],
 [0,0,0,0,0,0,1],
 [0,0,0,0,0,0,0],
 [0,0,0,0,0,0,0],
 [0,0,0,0,0,0,0],
 [0,1,0,0,0,1,1],
 [0,0,0,0,0,0,0]])

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.imshow(b)

有没有办法以任何想要的颜色(f.e. 黑色)绘制以下数组中 1 给出的像素?

a = np.array([[0,0,0,0,0,0,0],
     [0,0,0,0,0,0,1],
     [0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0],
     [0,1,0,0,0,1,1],
     [0,0,0,0,0,0,0]])

我的想法是在第一个透明的 imshow 上绘制第二个 imshow,但这显然行不通,因为它还会改变周围的像素。

您可能必须使用枚举获取 1 的索引,然后必须单独绘制像素。但是我还没有找到在 imshows 上绘制全像素的方法。我认为您可以在 imshows 上绘制图和点,但不能绘制全像素。我是对的还是我漏掉了什么?

感谢您的帮助!

liste = []
for index, value in np.ndenumerate(a):
        if value==1:
            liste.append(index)

for index in liste:
    index2 = (tuple(reversed((np.subtract(index, 0.5)))))
    rect = plt.Rectangle(index2, 1,1, color = 'red')
    ax.add_patch(rect)

结果:

似乎是使用矩形的作弊解决方案。这是我能做的最好的方法。