- 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 colorbars in Matplotlib?
To show multiple colorbars in matplotlib, we can take the following steps−
- Set the figure size and adjust the padding between and around the subplots.
- Create a figure and a set of subplots.
- Initialize a variable N for the number of sample data.
- Create random data1 using numpy.
- Display data as an image, i.e., on a 2D regular raster, with data1.
- Add a colorbar to a plot.
- Repeat steps 4, 5, and 6, with different datasets and axes.
- To display the figure, use show() method.
Example
from matplotlib import pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, (ax1, ax2) = plt.subplots(nrows=2, ncols=1) N = 10 data1 = np.random.rand(N, N) im1 = ax1.imshow(data1, cmap='hot') plt.colorbar(im1, cax=ax1) data2 = np.random.rand(N, N) im2 = ax2.imshow(data2, cmap='plasma') plt.colorbar(im2, cax=ax2) plt.show()
Output
- Related Articles
- How to build colorbars without attached plot in matplotlib?
- How to show multiple images in one figure in Matplotlib?
- Top label for Matplotlib colorbars
- How to show Matplotlib in Flask?
- How to plot multiple graphs in Matplotlib?
- How to show legend elements horizontally in Matplotlib?
- How to show two figures using Matplotlib?
- How to make Matplotlib show all X coordinates?
- How to give Matplolib imshow plot colorbars a label?
- How to show node name in Matplotlib graphs using networkx?
- How to plot multiple Seaborn Jointplot in Subplot using Matplotlib?
- How can I show figures separately in Matplotlib?
- How to display multiple images in one figure correctly in matplotlib?
- How to show mouse release event coordinates with Matplotlib?
- How to show multiple Canvases at the same time in Tkinter?

Advertisements