- 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 give Matplolib imshow plot colorbars a label?
To give matplotlib imshow() plot colorbars a label, we can take the following steps −
Set the figure size and adjust the padding between and around the subplots.
Create 5×5 data points using Numpy.
Use imshow() method to display the data as an image, i.e., on a 2D regular raster.
Create a colorbar for a ScalarMappable instance, im.
Set colorbar label using set_label() method.
To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.rand(5, 5) im = plt.imshow(data, cmap="copper") cbar = plt.colorbar(im) cbar.set_label("Colorbar") plt.show()
Output
- Related Articles
- Top label for Matplotlib colorbars
- How to build colorbars without attached plot in matplotlib?
- How to add a shared x-label and y-label to a plot created with Pandas' plot? (Matplotlib)
- Matplotlib – How to set xticks and yticks with imshow plot?
- How to plot data into imshow() with custom colormap in Matplotlib?
- How to draw a log-normalized imshow plot with a colorbar representing the raw data in Matplotlib?
- How to plot an emoji as a label for a bar in Matplotlib?
- How to show multiple colorbars in Matplotlib?
- How can I plot NaN values as a special color with imshow in Matplotlib?
- How to plot an image with non-linear Y-axis with Matplotlib using imshow?
- How to add a mathematical expression in axis label in a plot created by using plot function in R?
- How to label bubble chart/scatter plot with column from Pandas dataframe?
- How to convert the X-axis label in a bar plot to italic using ggplot2 in R?
- How do you just show the text label in a plot legend in Matplotlib?
- How to add legend to imshow() in Matplotlib?

Advertisements