Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Create a 3D scatter plot by making a Matplotlib axes with projection="3d", passing your x, y, and z coordinates to ax.scatter(), and labeling each axis. The example below uses repeatable sample data; replace it with your own three numeric variables.
Make a basic 3D scatter plot
Install Matplotlib and NumPy if they are not already available in your Python environment. Then run:
As an Amazon Associate I earn from qualifying purchases.
import matplotlib.pyplot as plt
import numpy as np
# Repeatable illustrative data, not a real dataset.
rng = np.random.default_rng(42)
n = 100
x = rng.uniform(0, 10, n)
y = rng.uniform(0, 10, n)
z = rng.uniform(0, 10, n)
fig = plt.figure()
ax = fig.add_subplot(projection="3d")
ax.scatter(x, y, z)
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
plt.show()
The seed makes this example’s sample values reproducible; it does not make the random points meaningful measurements. For a more compact figure-and-axes setup, Matplotlib also supports fig, ax = plt.subplots(subplot_kw={"projection": "3d"}) before calling ax.scatter(x, y, z). Both approaches create a 3D axes.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesHow the coordinates become points
ax = fig.add_subplot(projection="3d") creates the 3D axes, and ax.scatter(xs, ys, zs) plots the coordinates. Values correspond by position: the first x, y, and z values make one point, the second values make another, and so on. Supply coordinate arrays with matching lengths for the usual case. The API also permits zs to be a single scalar, which places all points at the same z position; its default is 0. See the Axes3D.scatter API reference and the official 3D scatter gallery example.
#1 Best Overall
For example, ax.scatter(x, y, z, zdir="y", zs=5) places the supplied two-dimensional data on the x-z plane, with the shared position of 5 along y. This is useful when plotting 2D coordinates on a plane inside the 3D axes; it is not the same as supplying a separate y-coordinate for every point.
Encode an additional variable with color or size
Scatter options can communicate more than the three spatial coordinates. The s parameter sets marker area in points squared and accepts either one value or per-point values. The c parameter accepts a color or per-point colors; numeric values can be mapped through a colormap and normalization. For example, using z for color adds a second visual cue for the same measurement:
Rank #2
points = ax.scatter(x, y, z, c=z, cmap="viridis", s=30)
fig.colorbar(points, ax=ax, label="Z value")
The colorbar explains what the colors mean. If color represents a different variable, label the colorbar with that variable instead. For categories, use distinct colors or marker shapes and include a clear legend. Avoid adding encodings that make the plot harder to read.
Recommended Free Tools
The depthshade option controls shading intended to suggest depth. Matplotlib applies it independently to each scatter call, so inspect the combined appearance when plotting multiple separately colored groups rather than assuming shading is applied globally. Details and defaults are in the scatter API reference.
Use version-specific scatter options carefully
The stable API reference identifies axlim_clip as added in Matplotlib 3.10; it hides points outside the axes’ view limits. It identifies depthshade_minalpha, which controls the minimum alpha used for depth shading, as added in Matplotlib 3.11. These options are unavailable in older versions, so check your installed Matplotlib version before using them. Stable documentation can change as releases advance.
Rotate the plot, then check whether 3D helps
Matplotlib’s mplot3d toolkit draws a 3D scene as a 2D projection. This can cause points to overlap, and viewing angle or perspective can make relationships and apparent distances difficult to interpret. Rotate the view and verify that the axis labels and scales make the plotted dimensions clear. If precise comparisons matter, consider pairwise 2D scatter plots, where each coordinate relationship is shown without a 3D projection.
With an interactive backend, you can rotate and zoom using mouse gestures. Toolbar pan and zoom buttons do not operate in the same way for 3D plots as they do for 2D plots; see Matplotlib’s interactivity guidance. The mplot3d toolkit documentation describes it as a simple plotting toolkit included with Matplotlib and notes that it is less mature than Matplotlib’s 2D plotting.
Do you need to import Axes3D?
Not for the modern setup shown here: fig.add_subplot(projection="3d") works without an explicit from mpl_toolkits.mplot3d import Axes3D import. Matplotlib’s guide says that explicit import ceased to be necessary in version 3.2.0, which explains why older tutorials may still include it. The mplot3d tutorial shows how to create 3D axes.
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.




