- 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 redefine a color for a specific value in a Matplotlib colormap?
To redefine a color for a specific value in matplotlib colormap, we can take the following steps −
Get a colormap instance, defaulting to rc values if *name* is None using get_cmap() method, with gray colormap.
Set the color for low out-of-range values when "norm.clip = False" using set_under() method.
Using imshow() method, display data an image, i.e., on a 2D regular raster.
To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt, cm plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True cmap = cm.get_cmap('gray') cmap.set_under('red') plt.imshow(np.arange(25).reshape(5, 5), interpolation='none', cmap=cmap, vmin=.001) plt.show()
Output
- Related Articles
- How to extract a subset of a colormap as a new colormap in Matplotlib?
- How to create a matplotlib colormap that treats one value specially?
- Plot a polar color wheel based on a colormap using Python/Matplotlib
- Defining a discrete colormap for imshow in Matplotlib
- How to set a default colormap in Matplotlib?
- How to color a Matplotlib scatterplot using a continuous value?
- How to display the matrix value and colormap in Matplotlib?
- How to shade points in a scatter based on colormap in Matplotlib?
- Defining the midpoint of a colormap in Matplotlib
- Set a colormap of an image in Matplotlib
- How to pick a new color for each plotted line within a figure in matplotlib?
- How to make the Parula colormap in Matplotlib?
- How to draw node colormap in NetworkX/Matplotlib?
- How to set a specific value for a range in an R vector?
- How to fill color below a curve in Matplotlib?

Advertisements