TypeError: 绘制图像时图像数据的形状 (100, 100, 1) 无效

Smu*_*ain 3 matplotlib python-3.x tensorflow

我尝试用 100,100,1 绘制图像,但出现这样的错误

TypeError: Invalid shape (100, 100, 1) for image data
Run Code Online (Sandbox Code Playgroud)

这是代码

sample_training_images, _ = next(traindata)
def plotImages(images_arr):
    fig, axes = plt.subplots(1, 5, figsize=(20,20))
    axes = axes.flatten()
    for img, ax in zip( images_arr, axes):
        ax.imshow(img)
        ax.axis('off')
    plt.tight_layout()
    plt.plot(images_arr)
    plt.show()

plotImages(sample_training_images[:5])
Run Code Online (Sandbox Code Playgroud)

Qua*_*ang 8

img用。。。来代替img[:,:,0]

 ax.imshow(img[:,:,0], cmap='gray')
Run Code Online (Sandbox Code Playgroud)

并且可能删除plt.plot(images_arr)