Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk2 min

How to Add Text to a Matplotlib Plot’s Corner or Center

Place text in a Matplotlib plot’s corner or center using Axes coordinates, with examples for corner alignment and guidance on when to use figure text or annotate.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

Use ax.text() with transform=ax.transAxes to place text relative to an Axes rather than at a data value. Axes coordinates run from (0, 0) at the lower-left to (1, 1) at the upper-right, so (0.5, 0.5) is the center.

Place text in a corner or the center of an Axes

This example adds an upper-left label and centered text to the same plot:

As an Amazon Associate I earn from qualifying purchases.

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot([0, 1, 2], [0, 1, 0])

# Upper-left, inset slightly from the Axes boundary.
ax.text(
    0.02, 0.98, "Upper-left label",
    transform=ax.transAxes,
    ha="left", va="top",
)

# Center of the Axes.
ax.text(
    0.5, 0.5, "Centered label",
    transform=ax.transAxes,
    ha="center", va="center",
)

plt.show()

The 0.02 and 0.98 values inset the corner label slightly from the edges. For the other corners, use an inset coordinate and match the alignment to that corner:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Upper right: x=0.98, y=0.98, ha="right", va="top"
  • Lower left: x=0.02, y=0.02, ha="left", va="bottom"
  • Lower right: x=0.98, y=0.02, ha="right", va="bottom"

These positions stay relative to the Axes rectangle when plotted data or axis limits change. See Matplotlib’s text properties and layout documentation.

Why the coordinate system matters

ax.text() and plt.text() use data coordinates by default. In that frame, a position such as (0.5, 0.5) means the data point x=0.5, y=0.5; it does not necessarily mean the visual center. A label placed at a data value moves on screen as the limits or data change.

Set transform=ax.transAxes when the location should track the plotting rectangle instead. This transform maps the Axes fractions (0, 0) and (1, 1) to its lower-left and upper-right corners. The examples use ax.text(), which is convenient when working with an Axes object; plt.text() can also be used with the appropriate transform. Matplotlib documents the behavior in its text API reference.

Align the text box to its anchor

The coordinates specify an anchor point, and alignment determines which part of the text box sits there. ha (horizontal alignment) accepts values such as "left", "center", or "right"; va (vertical alignment) accepts "bottom", "center", or "top". For example, ha="right", va="top" makes the text box’s upper-right meet its anchor. Explicit alignment avoids relying on the default left and baseline alignment. See Matplotlib’s alignment guidance.

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

Choose between Axes, figure, and data placement

Method and frame Follows data limits? Points to a data target? Best for
ax.text() with ax.transAxes: Axes rectangle No; position stays relative to the Axes. No Corner or center overlays inside one plot.
fig.text(): whole figure coordinates, from 0 to 1 by default No; position is relative to the figure. No Text positioned across the figure rather than within a particular Axes. See the Figure.text API.
ax.text() in its default data coordinates Yes; the location is a data value. It can label a value, but has no separate target and text positions. Text tied to a location in data space.
ax.annotate(): target and text can use coordinate systems such as data, Axes fraction, or figure fraction Depends on the coordinate system chosen for the target and text. Yes; target and text locations can be separate, with an optional arrow. Explanatory labels linked to a point. See Matplotlib’s text API reference.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When to use annotate instead

Use ax.annotate() when the label explains a particular point, especially if you want an arrow or need the target and displayed text in different places. Use Axes-relative ax.text() for a fixed corner or center label that is not tied to a specific data point.

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.