- 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 plot a density map in Python Matplotlib?
To plot a density map in Python, we can take the following steps −
Create side, x, y, and z using numpy. Numpy linspace helps to create data between two points based on a third number.
Return coordinate matrices from coordinate vectors using side data.
Create exponential data using x and y (Step 2).
Create a pseudocolor plot with a non-regular rectangular grid using pcolormesh() method.
To display the figure, use show() method.
Example
from matplotlib import pyplot as plt, cm, colors import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True side = np.linspace(-2, 2, 15) X, Y = np.meshgrid(side, side) Z = np.exp(-((X - 1) ** 2 + Y ** 2)) plt.pcolormesh(X, Y, Z, shading='auto') plt.show()
Output
- Related Articles
- How to plot a 3D density map in Python with Matplotlib?
- How to plot Time Zones in a map in Matplotlib
- How to plot a kernel density plot of dates in Pandas using Matplotlib?
- How to a plot stem plot in Matplotlib Python?
- Plot a black-and-white binary map in Matplotlib
- How can I make a scatter plot colored by density in Matplotlib?
- How to plot a multivariate function in Python Matplotlib?
- How to plot signal in Matplotlib in Python?
- How to plot cdf in Matplotlib in Python?
- How to plot a layered image in Matplotlib in Python?
- How to plot a phase spectrum in Matplotlib in Python?
- How to plot MFCC in Python using Matplotlib?
- How to plot vectors in Python using Matplotlib?
- How to save a plot in Seaborn with Python (Matplotlib)?
- How to plot magnitude spectrum in Matplotlib in Python?

Advertisements