- 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
Creating a 3D plot in Matplotlib from a 3D numpy array
To create a 3D plot from a 3D numpy array, we can create a 3D array using numpy and extract the x, y, and z points.
- 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.
- Create a random data of size=(3, 3, 3).
- Extract x, y, and z data from the 3D array.
- Plot 3D scattered points on the created axis
- 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 fig = plt.figure() ax = fig.add_subplot(111, projection='3d') data = np.random.random(size=(3, 3, 3)) z, x, y = data.nonzero() ax.scatter(x, y, z, c=z, alpha=1) plt.show()
Output
- Related Articles
- How to surface plot/3D plot from a dataframe (Matplotlib)?
- How to display a 3D plot of a 3D array isosurface in matplotlib mplot3D or similar?
- Creating 3D animation using matplotlib
- How to plot a 3D patch collection in matplotlib?
- How to plot a 3D continuous line in Matplotlib?
- Plot 3D bars without axes in Matplotlib
- Saving a 3D-plot in a PDF 3D with Python
- Plot Matplotlib 3D plot_surface with contour plot projection
- How to plot a point on 3D axes in Matplotlib?
- Setting the aspect ratio of a 3D plot in Matplotlib
- Plot a 3D surface from {x,y,z}-scatter data in Python Matplotlib
- How to plot a 3D density map in Python with Matplotlib?
- How to plot 3D graphs using Python Matplotlib?
- Make 3D plot interactive in Jupyter Notebook (Python & Matplotlib)
- Connecting two points on a 3D scatter plot in Python and Matplotlib

Advertisements