- 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 plot data into imshow() with custom colormap in Matplotlib?
To plot data into imshow() with custom colormap in matplotlib, we can take the following steps−
- Set the figure size and adjust the padding between and around the subplots.
- Create random data points using numpy.
- Generate a colormap object from a list of colors.
- Display the data as an image, i.e., on a 2D regular raster
- To display the figure, use show() method.
Example
from matplotlib import pyplot as plt from matplotlib.colors import ListedColormap import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.rand(5, 5) cmap = ListedColormap(['r', 'g', 'b']) plt.imshow(data, cmap=cmap) plt.show()
Output
- Related Articles
- Defining a discrete colormap for imshow in Matplotlib
- Matplotlib – How to set xticks and yticks with imshow plot?
- Matplotlib Plot Lines with Colors through Colormap
- How to draw a log-normalized imshow plot with a colorbar representing the raw data in Matplotlib?
- Set two Matplotlib imshow plots to have the same colormap scale
- Plot a histogram with colors taken from colormap in Matplotlib
- How to plot an image with non-linear Y-axis with Matplotlib using imshow?
- How can I plot NaN values as a special color with imshow in Matplotlib?
- How to plot 4D scatter-plot with custom colours and cutom area size in Python Matplotlib?
- How to create custom markers on a plot in Matplotlib
- How to add legend to imshow() in Matplotlib?
- How to use a custom png image marker in a plot (Matplotlib)?
- How to make a 4D plot with Matplotlib using arbitrary data?
- How to set a default colormap in Matplotlib?
- How to make the Parula colormap in Matplotlib?

Advertisements