What is the matplotlib.pyplot.imread() function in Python?
Overview
matplotlib is one of the multiple libraries provided by Python.
The main purpose of matplotlib is to provide us with data visualization. This library is based on numpy, and the purpose of designing this library is to work with the border SciPy stack.
Matplotlib has a sub-library known as pyplot, which makes it a visual open-source like Matlab.
imread() is a function provided by the matplotlib.pyplot library, and is used to read an image and store it in the form of an array.
Syntax
matplotlib.pyplot.imread(fname, format=None)
Parameters
fname: This is the name of the image to be read.format: This is the file format for reading images.
Return type
- This is an array that contains data for all the images.
Code
# Importing modulesimport matplotlib.pyplot as plt# Reading image using imreadimage=plt.imread("educative.jpeg")# Displaying read imageplt.imshow(image)
Explanation
-
Line 2: We import the
matplotlib.pyplotlibrary. -
Line 5: We read the image using the
imread()function. -
Line 8: We display the read image using
imshow().
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved