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
How to set a default colormap in Matplotlib?
To set a default colormap in matplotlib, we can take the following steps −
Create random data using numpy, array dimension 4×4.
Create two axes and one figure using subplots() method.
Display the data as an image with the default colormap.
Set the title of the image, for the default colormap.
Set the default colormap using matplotlib rcParams.
Display the data as an image, with set default colormap.
Set the title of the image, for the default colormap.
Adjust the padding between and around the subplots.
To display the figure, use show() method.
Example
import numpy as np
from matplotlib import pyplot as plt
import matplotlib as mpl
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
data = np.random.rand(4, 4)
fig, (ax1, ax2) = plt.subplots(2)
ax1.imshow(data)
ax1.set_title("Default colormap")
mpl.rc('image', cmap='RdYlBu_r')
ax2.imshow(data)
ax2.set_title("Set default colormap")
plt.show()
Output

Advertisements