- 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
Plot Matplotlib 3D plot_surface with contour plot projection
To plot 3d plot_surface with contour plot projection, we can use plot_surface() and contourf() methods.
Steps
Set the figure size and adjust the padding between and around the subplots.
Create x, y, X, Y and Z data points using numpy.
Create a new figure or activate an existing figure using figure() method.
Add an '~.axes.Axes' to the figure as part of a subplot arrangement, with 3D projection.
Use plot_surface() method to create a surface plot.
Create a 3D filled contour plotm using contourf() method.
Trurn off the axes.
To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.arange(-5, 5, 0.1) y = np.arange(-5, 5, 0.1) X, Y = np.meshgrid(x, y) Z = X * np.exp(-X - Y) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') surf = ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=1, cmap="copper") ax.contourf(X, Y, Z, zdir='z', offset=np.min(Z), cmap="plasma") ax.contourf(X, Y, Z, zdir='x', offset=-5, cmap="PiYG_r") ax.contourf(X, Y, Z, zdir='y', offset=5, cmap="PuBuGn") ax.axis('off') plt.show()
Output
- Related Articles
- How to surface plot/3D plot from a dataframe (Matplotlib)?
- Contour hatching in Matplotlib plot
- How to plot matplotlib contour?
- Plot scatter points on a 3D projection with varying marker size in Matplotlib
- Plot scatter points on 3d plot without axes and grids in Matplotlib
- Plot 3D bars without axes in Matplotlib
- Plot a 3D surface from {x,y,z}-scatter data in Python Matplotlib
- How to plot 3D graphs using Python Matplotlib?
- Draw axis lines or the origin for Matplotlib contour plot.
- How to plot a 3D density map in Python with Matplotlib?
- Creating a 3D plot in Matplotlib from a 3D numpy array
- Make 3D plot interactive in Jupyter Notebook (Python & Matplotlib)
- How to plot a 3D continuous line in Matplotlib?
- How to plot a 3D patch collection in matplotlib?
- Plot numpy datetime64 with Matplotlib

Advertisements