Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsTo add a label at a point in a Matplotlib 3D plot, call ax.text(x, y, z, "label") on the 3D axes. The coordinates are in your data space. For a note that should stay in a corner of the axes instead, use ax.text2D() with the axes transform.
Add a label at a 3D data point
Create an axes with the 3D projection, then pass the point’s x, y, and z coordinates followed by the text string:
As an Amazon Associate I earn from qualifying purchases.
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(projection="3d")
ax.scatter([1], [2], [3], color="navy")
ax.text(1, 2, 3, "point A", color="crimson")
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
plt.show()
The text position is specified in data coordinates, so use the same coordinate system as the plotted data. The Axes3D text API returns a Text3D artist and forwards styling keyword arguments to the ordinary Matplotlib text method. The official 3D text gallery example uses ax.text().
Choose between data-positioned and axes-positioned text
| Purpose | Method | Coordinate system |
|---|---|---|
| Attach a label to a location in the 3D scene | ax.text(x, y, z, s, ...) |
3D data coordinates |
| Keep explanatory text at a relative position, such as a corner | ax.text2D(x, y, s, transform=ax.transAxes) |
2D axes-relative coordinates |
Axes-relative coordinates run from (0, 0) at the lower-left to (1, 1) at the upper-right. For example:
#1 Best Overall
ax.text2D(0.05, 0.95, "Run 12", transform=ax.transAxes)
This keeps the note tied to the axes area rather than to a point in the 3D dataset. The gallery documents both placement approaches.
Control the text direction and style
Pass ordinary text styling options such as color and fontsize to ax.text():
Rank #2
ax.text(x, y, z, "peak", color="red", fontsize=10)
Use zdir when you want to set the direction of the text. Documented choices include "x", "y", "z", and three-component direction tuples such as (1, 1, 0). If you do not need a particular orientation, leave it at its default. See the gallery’s orientation examples for the supported patterns.
Clip labels to the axes limits
The axlim_clip argument hides text that lies outside the axes view limits when set to True. The Matplotlib API documents this option as added in version 3.10, so use it only when the installed Matplotlib version supports it:
ax.text(x, y, z, "label", axlim_clip=True)
In the documented API, axlim_clip defaults to False. Consult the API reference for its version and parameter details.
Quick Recap
Best Value
Avoid common placement mistakes
- Use the 3D axes method. Call
ax.text(x, y, z, "label"), notplt.text()with a presumed 3D signature. Matplotlib’s mplot3d overview explains that pyplot functions have 2D signatures and do not handle the additional information required for 3D content. - Pass coordinates before the string. The order is x, y, z, then the text:
ax.text(x, y, z, "label"). - Use the right coordinate system for the job. A point label belongs in data coordinates; a corner note belongs in axes-relative coordinates through
text2D. - Account for the camera view. Matplotlib’s
mplot3dprojects a 3D scene onto a 2D view. A label’s apparent position or overlap can change as the viewing angle changes. Adjust its data coordinates or camera view, style it for contrast, or use axes-relative text for notes that should remain in a fixed part of the axes.
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.




