If you are dealing with grayscale images, you should remove the channel dimension for matplotlib:
plt.imshow(np.random.randn(24, 24, 3)) # works
plt.imshow(np.random.randn(24, 24)) # works
plt.imshow(np.random.randn(24, 24, 1)) # fails