Displaying Images - ( Images in Matplotlib )
Heading h2
Syntax
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread('path/to/image.png')
plt.imshow(img)
plt.show()
Example
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread('sample_image.png')
plt.imshow(img)
plt.show()
Output
Displays the image 'sample_image.png' in a window.
Explanation
Matplotlib is a widely-used visualization library in Python. It is capable of displaying images in several formats and providing various types of visualizations.
In the above example, we first import both matplotlib.pyplot
and matplotlib.image
modules.
We then use mpimg.imread()
function to read the image file 'sample_image.png' from the file system.
After that, we use the imshow()
function to show the image and then finally call the show()
function to display the image in a window.
Use
Matplotlib is a powerful tool for visualizations in Python. It can be used to display images of various formats. It is commonly used in computer vision applications.
Important Points
- Matplotlib is a popular library in Python
matplotlib.image
module provides functions for reading and manipulating image filesmpimg.imread()
function is used to read the image filesimshow()
function is used to display the imageshow()
function is called to show the image in a window
Summary
In conclusion, matplotlib
is a powerful tool for creating visualizations in Python. It can be used to display images of various formats. mpimg.imread()
function reads the image file in matplotlib and imshow()
function is used to display the image. Finally, show()
function is called to show the image in a window.