- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 retrieve colorbar instance from figure in Matplotlib?
To retrieve colorbar instance from figure in matplotlib, we can use imshow scalar mappable object in colorbar to retrieve colorbar instance.
Steps
Get random data with 10×10 dimension of array, data points between -1 to 1.
Use imshow() method to display data as an image, i.e., on a 2D regular raster.
Create a colorbar for a ScalarMappable instance, *mappable*, with imshow() object.
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.randint(-1, 1, (10, 10)) im = plt.imshow(data, interpolation="nearest") cbar = plt.colorbar(im) plt.show()
Output
- Related Articles
- How to retrieve XY data from a Matplotlib figure?
- How to plot scatter points in a 3D figure with a colorbar in Matplotlib?
- How to decrease colorbar width in Matplotlib?
- How to animate the colorbar in Matplotlib?
- How to add Matplotlib Colorbar Ticks?
- How can I attach a pyplot function to a figure instance? (Matplotlib)
- How to shift the colorbar position to right in matplotlib?
- How to make colorbar orientation horizontal in Python using Matplotlib?
- How to add a colorbar for a hist2d plot in Matplotlib?
- How to plot a 2D matrix in Python with colorbar Matplotlib?
- How to plot a pcolor colorbar in a different subplot in Matplotlib?
- How to make a discrete colorbar for a scatter plot in matplotlib?
- How do I adjust (offset) the colorbar title in Matplotlib?
- How to change the font properties of a Matplotlib colorbar label?
- Matplotlib colorbar background and label placement

Advertisements