The Wayback Machine - https://web.archive.org/web/20250113220439/https://www.geeksforgeeks.org/matplotlib-pyplot-imread-in-python/
Open In App

matplotlib.pyplot.imread() in Python

Last Updated : 22 Apr, 2020
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface.

matplotlib.pyplot.imread() Function:

The imread() function in pyplot module of matplotlib library is used to read an image from a file into an array.

Syntax: matplotlib.pyplot.imread(fname, format=None)

Parameters: This method accepts the following parameters.

  • fname : This parameter is the image file to read.
  • format: This parameter is the image file format assumed for reading the data.

Returns: This method return the following.

  • imagedata : This returns the image data

Below examples illustrate the matplotlib.pyplot.imread() function in matplotlib.pyplot:

Example #1:




# Implementation of matplotlib function
import numpy as np
import matplotlib.cbook as cbook
import matplotlib.image as image
import matplotlib.pyplot as plt
  
with cbook.get_sample_data('loggf.png') as image_file:
    image = plt.imread(image_file)
  
fig, ax = plt.subplots()
ax.imshow(image)
ax.axis('off')
  
plt.title('matplotlib.pyplot.imread() function Example', 
                                     fontweight ="bold")
plt.show()


Output:

Example #2:




# Implementation of matplotlib function
import numpy as np
import matplotlib.cbook as cbook
import matplotlib.image as image
import matplotlib.pyplot as plt
  
  
with cbook.get_sample_data('loggf.png') as file:
    im = image.imread(file)
  
fig, ax = plt.subplots()
  
ax.plot(np.cos(10 * np.linspace(0, 1)), '-o', ms = 15,
                            alpha = 0.6, mfc ='green')
  
ax.grid()
fig.figimage(im, 10, 10, zorder = 3, alpha =.5)
  
plt.title('matplotlib.pyplot.imread() function Example', 
                                     fontweight ="bold")
plt.show()


Output:


Enhance your coding skills with DSA Python, a comprehensive course focused on Data Structures and Algorithms using Python. Over 90 days, you'll explore essential algorithms, learn how to solve complex problems, and sharpen your Python programming skills. This course is perfect for anyone looking to level up their coding abilities and get ready for top tech interviews.
Join the Three 90 Challenge and commit to completing 90% of the course in 90 days to earn a 90% refund. It’s the perfect way to stay focused, track your progress, and reap the rewards of your hard work. Take the challenge and become a DSA expert in Python today


Next Article
Article Tags :
Practice Tags :

Similar Reads

three90RightbarBannerImg