

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Plotting a 3D surface from a list of tuples in matplotlib?
To plot a 3D surface from a list of tuples in matplotlib, we can take the following steps.
Steps
Set the figure size and adjust the padding between and around the subplots.
Make a list of tuples.
Get the x, y and z data points from the list of tuples.
Return the coordinate matrices from the coordinate vectors.
Get the h data points for the surface plot.
Create a new figure or activate an existing figure.
Get the current axis, 3d, of the figure.
Create a surface plot.
To display the figure, use Show() method.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # List of tuples data = [(1, 3, 2), (3, 5, 2), (4, 7, 4), (8, 7, 4), (3, 6, 1), (3, 9, 0), (3, 9, 0)] # Data points from the list of tuples x, y, z = zip(*data) x, y = np.meshgrid(x, y) h = x ** 2 + y ** 2 fig = plt.figure() # Get the current axis ax = fig.gca(projection='3d') # Surface plot ax.plot_surface(x, y, h, cmap='plasma') plt.show()
Output
It will produce the following output −
- Related Questions & Answers
- How to surface plot/3D plot from a dataframe (Matplotlib)?
- Plotting a masked surface plot using Python, Numpy and Matplotlib
- Plot a 3D surface from {x,y,z}-scatter data in Python Matplotlib
- Plotting a 3d cube, a sphere and a vector in Matplotlib
- Plotting points on the surface of a sphere in Python's Matplotlib
- Plotting an imshow() image in 3d in Matplotlib
- Creating a 3D plot in Matplotlib from a 3D numpy array
- Find the Surface area of a 3D figure in Python
- Surface Area of 3D Shapes in Python
- Plotting a histogram from pre-counted data in Matplotlib
- Remove duplicate tuples from list of tuples in Python
- Python | Remove empty tuples from a list
- How to create a surface plot from a greyscale image with Matplotlib?
- Find the tuples containing the given element from a list of tuples in Python
- Plotting error bars from a dataframe using Seaborn FacetGrid (Matplotlib)
Advertisements