- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to display multiple images in one figure correctly in matplotlib?
To display multiple images in one figure, we can follow the steps given below −
Initialize the number of rows and cols. nrows*ncols subplot will be created in the current figure. nrows = 2 and ncols = 2, i.e., 2*2 = 4 subplots can be created.
Now add the figures at different indices from 1 to 4.
Use plt.subplot(2, 2, 1) to add new images, i.e., pie at index 1.
To plot a pie chart, pass a list of numbers. Pie charts will be split into the size of list and %age section will depend upon the values in the list.
Set the title of the subplot, i.e., “Figure 1”.
Use plt.subplot(2, 2, 2) to add new images, i.e., pie at index 2.
Use plt.pie() to create a new pie chart.
Set the title of the subplot, i.e., “Figure 2”.
Use plt.subplot(2, 2, 3) to add new images i.e., pie at index 3.
Use plt.pie() to create a new pie chart.
Set the title of the subplot i.e., “Figure 3”.
Use plt.subplot(2, 2, 4) to add new images i.e., pie at index 4.
Use plt.pie() to create a new pie chart.
Set the title of the subplot i.e., “Figure 4”.
Use plt.show(), to show the figure.
Example
import matplotlib.pyplot as plt rows, cols = 2, 2 plt.subplot(rows, cols, 1) plt.pie([1, 2, 3]) plt.title("Figure 1") plt.subplot(rows, cols, 2) plt.pie([3, 4, 5]) plt.title("Figure 2") plt.subplot(rows, cols, 3) plt.pie([6, 7, 8]) plt.title("Figure 3") plt.subplot(rows, cols, 4) plt.pie([8, 9, 10]) plt.title("Figure 4") plt.show()
Output
- Related Articles
- How to show multiple images in one figure in Matplotlib?
- How to display a sequence of images using Matplotlib?
- How to view multiple images in JavaFX?
- How to display Base64 images in HTML?
- Combine multiple images using one dockerfile
- How to use multiple font sizes in one label in Python Matplotlib?
- How to plot multiple horizontal bars in one chart with matplotlib?
- How to display multiple labels in one line with Python Tkinter?
- How to display animated gif images in Android?
- Saving multiple figures to one PDF file in matplotlib
- How to set local rcParams or rcParams for one figure in matplotlib?
- How can multiple plots be plotted in same figure using matplotlib and Python?
- How to combine several matplotlib axes subplots into one figure?
- How to plot multiple graphs in Matplotlib?
- How to show multiple colorbars in Matplotlib?
