Matplotlib imshow: Display Images with plt.imshow
The plt.imshow() function is used to display images or arrays. Its syntax is as follows:
plt.imshow(X, cmap=None)
In this case, X is the image or array to be displayed, and cmap is the parameter used to specify the color mapping, an optional parameter.
Here is an example of displaying an image using plt.imshow() function.
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
# 读取图像
img = mpimg.imread('image.jpg')
# 显示图像
plt.imshow(img)
plt.axis('off') # 关闭坐标轴
plt.show()
In the example above, the image file is first read using the mpimg.imread() function, then displayed with the plt.imshow() function. The axis is turned off using plt.axis(‘off’), and finally the image is shown using plt.show().