To plot an (N, 3) NumPy array in 3D, create a Matplotlib axes with projection="3d" and pass its three columns to ax.scatter(): the first column is x, the second y, and the third z.
Plot an N-by-3 array in 3D
Each row below represents one point, with its x, y, and z coordinates in that order. The 3D scatter method belongs to the projected axes, so call ax.scatter() rather than the ordinary 2D plt.scatter() function.
import matplotlib.pyplot as plt
import numpy as np
# One point per row; columns are x, y, and z.
points = np.array([
[0.0, 1.0, 2.0],
[1.0, 0.5, 3.0],
[2.0, 2.0, 1.0],
])
fig = plt.figure()
ax = fig.add_subplot(projection="3d")
ax.scatter(points[:, 0], points[:, 1], points[:, 2])
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
plt.show()
This follows Matplotlib’s documented 3D scatter plot example: set up a 3D subplot, then pass the coordinate sequences to its scatter method.
How the columns map to coordinates
For an array with shape (N, 3), N is the number of points and each of the three columns contains one coordinate for every point:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
points[:, 0]supplies x coordinates.points[:, 1]supplies y coordinates.points[:, 2]supplies z coordinates.
The slices select every row in one column. Keep the coordinate arrays aligned: x, y, and z should each contain one value per plotted point. The Axes3D.scatter API accepts array-like x and y positions and either an array-like z sequence or a scalar z value. A scalar places all points at that same height, which is useful for a flat plane but not for plotting three distinct columns.
Use an alternative 3D axes setup
You can create the same kind of axes with plt.subplots() by specifying its projection in subplot_kw:
Rank #2
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
ax.scatter(points[:, 0], points[:, 1], points[:, 2])
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
plt.show()
Both approaches create a Matplotlib Axes3D object. The mplot3d toolkit documentation explains how the projection="3d" setting selects it.
Change marker size or color
Pass optional arguments to ax.scatter() to adjust the points. For example, use a numeric array as c to color points according to a fourth measurement, such as a value stored separately from the three coordinates:
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minutevalues = np.array([10, 20, 30])
ax.scatter(
points[:, 0],
points[:, 1],
points[:, 2],
s=40,
c=values,
cmap="viridis",
)
Here s sets marker area in points squared, while numeric c values are mapped through the selected colormap. The API also allows a single color or per-point colors. See the scatter parameter reference for the available options, including depthshade, which controls depth shading.
Rotate the plot and understand its limits
Matplotlib’s mplot3d displays a projection of a 3D scene. In interactive backends, you can drag the plot to rotate the view and use the mouse to zoom. It is a convenient choice when you want a 3D plot within Matplotlib, but Matplotlib’s mplot3d overview cautions that it is not the fastest or most feature-complete 3D library.
The axlim_clip option for hiding points outside the axes view limits was added in Matplotlib 3.10. Use it only when running that version or newer; consult the API documentation for its exact behavior.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




