

- 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
How to add a 3d subplot to a matplotlib figure?
To add a 3D subplot to a matplotlib figure, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create x, y and z data points using numpy.
- Create a new figure or activate an existing figure.
- Add an 'ax' to the figure as part of a subplot arrangement with projection='3d'.
- Plot x, y and z data points using plot() method.
- To display the figure, use .show() method.
Example
from matplotlib import pyplot as plt import numpy as np # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create x, y and z data points using numpy x = np.linspace(-5, 5, 100) y = np.linspace(-5, 5, 100) z = x ** 2 + y ** 2 fig = plt.figure() # add subplot with projection='3d' ax = fig.add_subplot(111, projection='3d') # Plot x, y and z data points ax.plot(x, y, z, color='red', lw=7) plt.show()
Output
It will produce the following output −
- Related Questions & Answers
- How to add a 3d subplot to a matplotlib figure?\n
- How to plot scatter points in a 3D figure with a colorbar in Matplotlib?
- How to rotate tick labels in a subplot in Matplotlib?
- How to retrieve XY data from a Matplotlib figure?
- How to position and align a Matplotlib figure legend?
- How to set the margins of a Matplotlib figure?
- How to plot a pcolor colorbar in a different subplot in Matplotlib?
- Add a legend in a 3D scatterplot with scatter() in Matplotlib
- Stuffing a Pandas DataFrame.plot into a Matplotlib subplot
- Matplotlib figure to image as a numpy array
- How to plot a 3D continuous line in Matplotlib?
- How to plot a 3D patch collection in matplotlib?
- How can I attach a pyplot function to a figure instance? (Matplotlib)
- How to have a function return a figure in Python (using Matplotlib)?
- How to create a legend for a 3D bar in Matplotlib?
- Matplotlib legends in subplot
Advertisements