首页 > 解决方案 > 为什么 pyplot imshow 与其颜色条不匹配?

问题描述

imshow彩条问题

问题是:如何用相同的黑色表示不同的值(0 和 255)?并且相同的值(255)也以黑白显示?

我的代码如下:

 #Vizualizing grayscale
def visualize_input(img,ax):
   pos=ax.imshow(img,cmap='gray')
   width,height=img.shape
   #thresh = img.max()
   for x in range (width):
    for y in range(height):
        ax.annotate(str(round(img[x][y],2)), xy=(x,y),
                    horizontalalignment='center',
                    verticalalignment='center',
                    color='blue') #if img[x][y]<=thresh else 'black')
   plt.colorbar(pos)          

fig=plt.figure(figsize=(15,15))
ax=fig.add_subplot()
visualize_input(X_train[0].reshape(28,28),ax)

任何有用的帮助!

标签: pythonmatplotlibimshow

解决方案


The problem was that due to FOR order i had to set xy=(y,x).


推荐阅读