What is the pyplot.imshow() method?

Matplotlib is a package in Python that is primarily used for plotting. It works in a way that emulates MATLAB. However, it can also be used to display images on the screen with the help of pyplot.im.show().

Code

The following image will be loaded in the examples below:

educative.png
educative.png

Using pyplot.im.show() with the default parameters

# Importing dependancies
import matplotlib.pyplot as pyplot
import matplotlib.image as mpimg
# loading the image
image = mpimg.imread("educative.png")
# displaying the image
pyplot.imshow(image)
pyplot.show()
Output of the above code
Output of the above code

Using pyplot.im.show() to convert an image to gray-scale

# importing the dependencies
import matplotlib.pyplot as pyplot
import matplotlib.image as mpimg
# loading the image
image = mpimg.imread("educative.png")
img = image[:,:,0]
# cmap = grey sets the image to grayscale
# Interpolation calculates what the color or value of a pixel “should” be, according
# to different mathematical schemes. Setting it to bicubic means that
# the image will get blurred instead of getting pixelated
pyplot.imshow(img, cmap = "gray", interpolation = 'BICUBIC')
# We dont want the axis values that were displayed in the previous example.
pyplot.axis("off")
pyplot.show()
Output of the above code
Output of the above code

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved