- 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
Saving a 3D-plot in a PDF 3D with Python
To save a 3D-plot in a PDF with Python, we can take the following steps
Steps
Set the figure size and adjust the padding between and around the subplots.
Create a new figure or activate an existing figure.
Add an 'ax' to the figure as part of a subplot arrangement.
Create u, v, x, y and z data points using numpy.
Plot a 3D wireframe.
Set the title of the plot.
Save the current figure using savefig() method.
Example
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(111, projection='3d') u, v = np.mgrid[0:2 * np.pi:30j, 0:np.pi:20j] x = np.cos(u) * np.sin(v) y = np.sin(u) * np.sin(v) z = np.cos(v) ax.plot_wireframe(x, y, z, color="red") ax.set_title("Sphere") plt.savefig("test.pdf") plt.show()
Output
It will produce the following output −
Also, it will create a PDF called test.pdf in the project directory and save this image in that file.
- Related Articles
- Creating a 3D plot in Matplotlib from a 3D numpy array
- How to plot a 3D density map in Python with Matplotlib?
- How to make a 3D scatter plot in Python?
- Plot Matplotlib 3D plot_surface with contour plot projection
- How to display a 3D plot of a 3D array isosurface in matplotlib mplot3D or similar?
- How to plot 3D graphs using Python Matplotlib?
- Connecting two points on a 3D scatter plot in Python and Matplotlib
- Make 3D plot interactive in Jupyter Notebook (Python & Matplotlib)
- How to surface plot/3D plot from a dataframe (Matplotlib)?
- How to plot a 3D continuous line in Matplotlib?
- How to plot a 3D patch collection in matplotlib?
- How to plot scatter points in a 3D figure with a colorbar in Matplotlib?
- Plot a 3D surface from {x,y,z}-scatter data in Python Matplotlib
- Plot scatter points on a 3D projection with varying marker size in Matplotlib
- Setting the aspect ratio of a 3D plot in Matplotlib

Advertisements