- 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 a 3D surface from {x,y,z}-scatter data in Python Matplotlib
To plot a 3D surface from x, y and z scatter data in Python, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create a new figure or activate an existing figure using figure() method.
- Add an axes to the figure as part of a subplot arrangement.
- Create x, y, X, Y and Z data points using numpy.
- Plot x, y and z data points using plot_surface() method.
- To display the figure, use show() method.
Example
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(111, projection='3d') x = np.array(np.linspace(-2, 2, 100)) y = np.array(np.linspace(-2, 2, 10)) X, Y = np.meshgrid(x, y) Z = X * np.exp(-X ** 2 - Y ** 2) ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap="plasma", linewidth=0, antialiased=False) plt.show()
Output
- Related Articles
- How to surface plot/3D plot from a dataframe (Matplotlib)?
- Connecting two points on a 3D scatter plot in Python and Matplotlib
- Controlling the alpha value on a 3D scatter plot using Python and Matplotlib
- Plot scatter points on 3d plot without axes and grids in Matplotlib
- How to make a 3D scatter plot in Python?
- Plot scatter points on a 3D projection with varying marker size in Matplotlib
- How to plot scatter points in a 3D figure with a colorbar in Matplotlib?
- Creating a 3D plot in Matplotlib from a 3D numpy array
- How to turn off transparency in Matplotlib's 3D Scatter plot?
- How to plot a smooth 2D color plot for z = f(x, y) in Matplotlib?
- Evaluate a 3D Legendre series at points (x, y, z) in Python
- Evaluate a 3D Laguerre series at points (x,y,z) in Python
- Python Scatter Plot with Multiple Y values for each X
- Subtract x²-y²+z² from x²-y²- z²
- Plotting a 3D surface from a list of tuples in matplotlib?

Advertisements