Use Matplotlib’s 3D axes and pass a numeric array to c to color each point by a value. Pair that mapping with a colormap and colorbar so readers can interpret the colors. For categories, use explicit group colors and a legend instead.
Create a 3D scatter plot colored by a numeric value
Each observation needs matching x, y, z coordinates and a color value. This example uses one value per point and labels the color scale.
import matplotlib.pyplot as plt
import numpy as np
# Each array contains one entry per observation.
x = np.array([1, 2, 3, 4])
y = np.array([2, 1, 4, 3])
z = np.array([0.5, 1.2, 0.7, 1.8])
values = np.array([10, 25, 40, 60])
fig = plt.figure()
ax = fig.add_subplot(projection="3d")
points = ax.scatter(x, y, z, c=values, cmap="viridis")
fig.colorbar(points, ax=ax, label="Measured value")
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
plt.show()
The 3D axes are created with projection="3d", and ax.scatter(x, y, z, ...) plots the coordinates. Matplotlib maps the numeric c values through the selected cmap; the colorbar, linked to the returned scatter object, explains that mapping. Replace “Measured value” with the quantity and units represented by your data. The official 3D scatterplot example shows the basic 3D scatter workflow.
Choose colors that match what the data means
Continuous numeric values
Use one numeric value per point in c, choose a colormap suited to the quantity, and add a labeled colorbar. Matplotlib also accepts norm to control how values are scaled into the colormap. See the Axes3D.scatter API for the supported color inputs and mapping options.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
Discrete categories
For groups such as “A,” “B,” and “C,” assign deliberate colors to each category—either by supplying explicit colors per point or by plotting each group separately with a fixed color. Identify the groups with a legend. A continuous-looking colorbar suggests a numeric scale, so it is not a suitable key for unordered categories.
One uniform color
If all points should have the same color, pass a named color or color format rather than a numeric array. This avoids implying that color varies with a data value.
Rank #2
Check the data and rendering
- Make sure
x,y,z, and per-pointcvalues have the same number of entries and refer to the same observations. - Use a colorbar for a continuous numeric mapping and a legend for category colors.
depthshadechanges marker rendering to suggest depth; it is enabled by default in the current API documentation. It is separate from the data-to-color mapping, so it should not be used as a substitute for a colormap or key.
Matplotlib describes mplot3d as a simple 3D plotting toolkit and notes that 3D plotting is less mature than 2D. Interactive backends can allow rotation and zooming, which may help inspect points from different angles. See the mplot3d toolkit documentation.
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.
Free tools Windows power users keep installed
One-click scans. No signup required.




