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.
The imread() function in pyplot module of matplotlib library is used to read an image from a file into an array.
Python3 1==
Output:
Example #2:
Python3 1==
matplotlib.pyplot.imread() Function:
Syntax: matplotlib.pyplot.imread(fname, format=None) Parameters: This method accepts the following parameters.Below examples illustrate the matplotlib.pyplot.imread() function in matplotlib.pyplot: Example #1:Returns: This method return the following.
- fname : This parameter is the image file to read.
- format: This parameter is the image file format assumed for reading the data.
- imagedata : This returns the image data
# 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()
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:

