
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
How to plot a 3D density map in Python with Matplotlib?
To plot a 3D density map in Python with matplotlib, 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 the 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 density map in Python Matplotlib?
- How to plot 3D graphs using Python Matplotlib?
- How to surface plot/3D plot from a dataframe (Matplotlib)?
- Plot Matplotlib 3D plot_surface with contour plot projection
- How to plot a 3D continuous line in Matplotlib?
- How to plot a 3D patch collection in matplotlib?
- Saving a 3D-plot in a PDF 3D with Python
- How to plot scatter points in a 3D figure with a colorbar in Matplotlib?
- How to plot a point on 3D axes in Matplotlib?
- How to plot a kernel density plot of dates in Pandas using Matplotlib?
- How to plot Time Zones in a map in Matplotlib
- Creating a 3D plot in Matplotlib from a 3D numpy array
- Make 3D plot interactive in Jupyter Notebook (Python & Matplotlib)
- How to hide axes but keep axis-labels in 3D Plot with Matplotlib?
- How to display a 3D plot of a 3D array isosurface in matplotlib mplot3D or similar?

Advertisements