- 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 create a standard colorbar for a series of plots in Python?
To create a standard colorbar for a series of plots, we can take the following steps −
Create random data using numpy.
Create a figure and a set of subplot using subplots() method, where nrows=1 and ncols=1.
Display data as an image.
Add an axes to the figure, for colorbar.
Create a colorbar where mappable instance is image and cax where color will be drawn.
To display the figure, use show() method.
Example
import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.rand(4, 4) fig, ax = plt.subplots(nrows=1, ncols=1) im = ax.imshow(data) cax = fig.add_axes([0.9, 0.1, 0.03, 0.8]) fig.colorbar(im, cax=cax) plt.show()
Output
Advertisements