- 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 show multiple images in one figure in Matplotlib?
To show multiple images in one figure in matplotlib, we can take the following steps −
Create random data using numpy.
Add a subplot to the current figure, nrows=1, ncols=4 and at index=1.
Display data as an image, i.e., on a 2D regular raster, using imshow() method with cmap="Blues_r".
Add a subplot to the current figure, nrows=1, ncols=4 and at index=2.
Display data as an image, i.e., on a 2D regular raster, using imshow() method with cmap="Accent_r".
Add a subplot to the current figure, nrows=1, ncols=4 and at index=3.
Display data as an image, i.e., on a 2D regular raster, using imshow() method with cmap="terrain_r".
Add a subplot to the current figure, nrows=1, ncols=4 and at index=4.
Display data as an image, i.e., on a 2D regular raster, using imshow() method with cmap="twilight_shifted_r".
To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.rand(5, 5) plt.subplot(1, 4, 1) plt.imshow(data, cmap="Blues_r") plt.subplot(1, 4, 2) plt.imshow(data, cmap="Accent_r") plt.subplot(1, 4, 3) plt.imshow(data, cmap="terrain_r") plt.subplot(1, 4, 4) plt.imshow(data, cmap="twilight_shifted_r") plt.show()
Output
- Related Articles
- How to display multiple images in one figure correctly in matplotlib?
- How to show multiple colorbars in Matplotlib?
- How to show a figure that has been closed in Matplotlib?
- Combine multiple images using one dockerfile
- How to view multiple images in JavaFX?
- How can I get pyplot images to show on a console app? (Matplotlib)
- How to plot multiple horizontal bars in one chart with matplotlib?
- How to use multiple font sizes in one label in Python Matplotlib?
- Saving multiple figures to one PDF file in matplotlib
- How to set local rcParams or rcParams for one figure in matplotlib?
- How to show Matplotlib in Flask?
- How to combine several matplotlib axes subplots into one figure?
- How can multiple plots be plotted in same figure using matplotlib and Python?
- Combining multiple images into a single one using JavaScript
- How to plot multiple graphs in Matplotlib?
