iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
To add text at a point in a Matplotlib 3D plot, call ax.text(x, y, z, "label") on the 3D axes object. The three coordinates are in data units. For a note that should stay in a fixed corner instead, use ax.text2D() with the axes transform.
Add text at a 3D data point
Create a 3D axes, then pass its x, y and z position followed by the text string to ax.text():
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()
Here, (1, 2, 3) identifies the text position in the plot’s data coordinates. The 3D axes method returns a text artist, and accepts standard text styling options such as color and fontsize. See Matplotlib’s 3D text annotation example and Axes3D text API reference.
Free tools Windows power users keep installed
One-click scans. No signup required.
Choose between data-positioned and axes-positioned text
The right method depends on whether the text belongs to a 3D location or should remain in a consistent screen-relative position:
#1 Best Overall
| Need | Method | Coordinates |
|---|---|---|
| Label a location in the 3D scene | ax.text(x, y, z, s) |
3D data coordinates |
| Keep a note at a relative position within the axes | ax.text2D(x, y, s, transform=ax.transAxes) |
2D axes-relative coordinates |
Keep an explanatory note in a corner
For a label such as a run name or brief note that should not be attached to a plotted point, use text2D():
ax.text2D(0.05, 0.95, "Run 12", transform=ax.transAxes)
With ax.transAxes, (0, 0) is the lower-left of the axes and (1, 1) is the upper-right. Values such as (0.05, 0.95) place text near the upper-left.
Rank #2
Control the direction of 3D text
Use the zdir argument when the text should be oriented relative to a chosen direction. The gallery documents axis names such as "x", "y", and "z", as well as three-component direction tuples such as (1, 1, 0). For ordinary point labels, leave the default orientation. Because Matplotlib projects the 3D scene onto a 2D view, the text’s apparent position and overlap can change as the camera view changes. The official example shows the available direction forms.
Recommended Free Tools
Avoid common 3D text mistakes
- Use the axes method, not
plt.text(). Matplotlib’s pyplot text functions use 2D signatures; callax.text()on the 3D axes to provide the extra coordinate. See the mplot3d toolkit overview. - Pass arguments in the right order. Use
ax.text(x, y, z, "label"): the full coordinate triple comes before the string. - Choose the coordinate system deliberately. Use
text2D()for a fixed axes-relative note, not for a label anchored to a 3D data position. - Account for the viewing angle. If a label overlaps plotted data or becomes difficult to read, adjust its coordinates, camera view, or styling; for a non-data note, use axes-relative text.
Clip text beyond the view limits (Matplotlib 3.10 and later)
The axlim_clip argument is documented as added in Matplotlib 3.10. It defaults to False; set it to True to hide text outside the axes’ view limits:
ax.text(x, y, z, "label", axlim_clip=True)
Use this option only with Matplotlib 3.10 or later. The version requirement and default are listed in the text API reference.
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.

