October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

Matplotlib 3D Plot Text: Add Data Labels and Fixed Notes in Python

Use ax.text(x, y, z, "label") to annotate a data point in a Matplotlib 3D plot, or ax.text2D() for a note placed relative to the axes.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To 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().

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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:

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():

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

Avoid common placement mistakes

  • Use the 3D axes method. Call ax.text(x, y, z, "label"), not plt.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 mplot3d projects 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.