- 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 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
- Related Articles
- Set a colormap of an image in Matplotlib
- How to extract a subset of a colormap as a new colormap in Matplotlib?
- How to draw node colormap in NetworkX/Matplotlib?
- How to make the Parula colormap in Matplotlib?
- Set two Matplotlib imshow plots to have the same colormap scale
- How to set the matplotlib figure default size in ipython notebook?
- How to increase colormap/linewidth quality in streamplot Matplotlib?
- How to shade points in a scatter based on colormap in Matplotlib?
- How to redefine a color for a specific value in a Matplotlib colormap?
- How to display the matrix value and colormap in Matplotlib?
- How to create a matplotlib colormap that treats one value specially?
- Defining the midpoint of a colormap in Matplotlib
- Defining a discrete colormap for imshow in Matplotlib
- Extract Matplotlib colormap in hex-format
- How to plot data into imshow() with custom colormap in Matplotlib?

Advertisements