
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Top Label for Matplotlib Colorbars
To place a top label for colorbars, we can use colorbar's axis to set the title.
Steps
- Create random data using numpy.
- Use imshow() method to represent data into an image, with colormap "PuBuGn" and interpolation= "nearest".
- Create a colorbar for a scalar mappable instance, im
- Set the title on the ax (of colorbar) using set_title() method.
- 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.randn(4, 4) im = plt.imshow(data, interpolation='nearest', cmap="PuBuGn") clb = plt.colorbar(im) clb.ax.set_title('Color Bar Title') plt.show()
Output
Advertisements