Matplotlib Example | Display an Image with Grayscale

It is very easy to display an image with grayscale in matplotlib, we will use an example to introduce how to do.

Display an image with grayscale in matplotlib

Here is a simple example code:

import matplotlib.pyplot as plt
import matplotlib.image as img

image = img.imread('img.jpg')

plt.imshow(image[:,:,1], cmap='gray')
plt.show()

Run this code, we will see an grayscale image.

Matplotlib Example | Display an Image with Grayscale