- 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 surface plot/3D plot from a dataframe (Matplotlib)?
To surface plot/3d, we would require 2D data points, not 1D dataframe.
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.Axes' to the figure as part of a subplot arrangement using add_subplot() method.
Initialize a variable 'n' for the number of samples.
Create x, y and z data points using numpy.
Use plot_surface() method to make surface 3d.
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 fig = plt.figure() ax = fig.add_subplot(111, projection='3d') n = 50 x = np.random.rand(n) y = np.tan(x) z = np.random.rand(n, n) surf = ax.plot_surface(y, x, z, rstride=1, cstride=1, cmap='copper',linewidth=0, antialiased=False) ax.axis('off') plt.show()
Output
- Related Articles
- Plot a 3D surface from {x,y,z}-scatter data in Python Matplotlib
- Creating a 3D plot in Matplotlib from a 3D numpy array
- Plot Matplotlib 3D plot_surface with contour plot projection
- How to plot a Pandas Dataframe with Matplotlib?
- How to plot a 3D patch collection in matplotlib?
- How to plot a 3D continuous line in Matplotlib?
- How to plot 3D graphs using Python Matplotlib?
- Annotating points from a Pandas Dataframe in Matplotlib plot
- How to create a surface plot from a greyscale image with Matplotlib?
- How to plot a point on 3D axes in Matplotlib?
- How to plot a 3D density map in Python with Matplotlib?
- Plot 3D bars without axes in Matplotlib
- How to plot certain rows of a Pandas dataframe using Matplotlib?
- How to display a 3D plot of a 3D array isosurface in matplotlib mplot3D or similar?
- Plot scatter points on 3d plot without axes and grids in Matplotlib

Advertisements