How to Display Multiple Images in One Figure Correctly in Matplotlib?
The easiest way to display multiple images in one figure is use figure(), add_subplot(), and imshow() methods of Matplotlib. The approach which is used to follow is first initiating fig object by calling fig=plt.figure() and then add an axes object to the fig by calling add_subplot() method. Then will display the image using imshow() method.
Syntax: add_subplot(rows, columns, i)
Here rows and columns are the total number of rows and columns in the figure and i is the position at which new subplot must be placed.
- Import required libraries
- Create a figure
- Set values of rows and column variables
- Read images
- Add subplot and display image one by one
Consider below Images used as input:
Below is the implementation :
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course