Plot Annotation

A plot is only as useful as the text around it. Plot annotation is the set of titles, axis labels, tick labels, legends and pointed notes that let a reader decode a figure without asking you what it shows. In scientific computing you will produce plots constantly, for lab reports, for debugging and for published results. A handful of annotation choices decides whether a figure works as evidence or leaves the reader guessing. This lesson covers what to label, how to place text exactly where you want it, and how a logarithmic scale changes where things land.

What a reader needs from the figure

A reader scanning a figure asks four questions: what was measured, in what units, which curve is which, and what should I notice? Each annotation element answers one of them.


Element

Question it answers

Matplotlib call

Title or caption

What does this figure show?

ax.set_title(...)

Axis labels

Which quantity, in which unit?

ax.set_xlabel(...), ax.set_ylabel(...)

Tick labels

What value sits at each mark?

ax.set_xticks(...)

Legend

Which series is which?

label= in each plot call, then ax.legend()

Annotation

Which feature matters?

ax.annotate(...)


An axis label names the quantity, then gives its unit in parentheses: Time (s), Temperature (°C). The unit in the label must describe the numbers actually plotted. If your array holds pascals and you want kilopascals on the axis, divide the data by 1000 before plotting. Editing only the label makes every tick value wrong by a factor of 1000. Greek letters and subscripts can be written with Matplotlib's mathtext, so a label can read τ or Vout instead of tau or Vout.


An annotation is a piece of text, usually joined to an arrow, that is attached to one point on the plot to direct attention to a single feature such as a peak, a threshold crossing or a time constant. Use one or two per figure. A plot covered in arrows hides the very features the arrows are meant to show.


Python
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot(t, T_model, "-", label="Model")
ax.plot(t_meas, T_meas, "o", label="Measured")
ax.set_title("Cooling of a copper block")
ax.set_xlabel("Time (s)")
ax.set_ylabel("Temperature (°C)")
ax.set_xlim(0, 60)
ax.set_ylim(20, 100)
ax.legend(loc="upper right")
ax.annotate("Time constant, 20 s", xy=(20, 45.8), xytext=(0.48, 0.63),
            textcoords="axes fraction", arrowprops={"arrowstyle": "->"})


A line plot of temperature against time for a cooling copper block with a title, labelled axes, a legend for model and measured data, and an arrow annotation at 20 s.



Placing text: data versus axes coordinates

In the call above, xy=(20, 45.8) is given in data coordinates, the same units as the plotted values: 20 s and 45.8 °C. The text position uses axes coordinates, fractions of the plotting area that run from 0 at the left and bottom edges to 1 at the right and top edges. On a linear axis you convert between them with


fx=x−xmin⁡xmax⁡−xmin⁡f_x = \frac{x - x_{\min}}{x_{\max} - x_{\min}}


where xmin⁡x_{\min} and xmax⁡x_{\max} are the axis limits and fxf_x is the axes fraction. The same rule applies vertically with the y-limits.


Example: On an axis set to 0–60 s, an event at 45 s sits at fx=(45−0)/(60−0)=0.75f_x = (45 - 0)/(60 - 0) = 0.75, three-quarters of the way across.


Property

Data coordinates

Axes coordinates

Units

Same as the plotted values

Fraction of the plotting area, 0 to 1

After changing axis limits

Moves with the data

Stays at the same spot on screen

Typical use

Arrow tip on a data feature

Panel letter or note in a corner

Matplotlib setting

xycoords="data" (the default)

textcoords="axes fraction" or transform=ax.transAxes


Logarithmic axes

When values span several orders of magnitude, a linear axis crushes the small values against one edge. A logarithmic axis, set with ax.set_yscale("log"), places equal ratios at equal distances, so each factor of 10, one decade, gets the same length. Position on a log axis follows the linear rule applied to logarithms:


fx=log⁡10x−log⁡10xmin⁡log⁡10xmax⁡−log⁡10xmin⁡f_x = \frac{\log_{10} x - \log_{10} x_{\min}}{\log_{10} x_{\max} - \log_{10} x_{\min}}


Example: On an axis from 1 to 1000, the value 10 sits at fx=(1−0)/(3−0)=0.333f_x = (1 - 0)/(3 - 0) = 0.333, one-third of the way across, whereas a linear axis with the same limits would put it at about 0.009, almost on the left edge.


Limits on a log axis must be positive: zero and negative values have no logarithm, so set limits such as 0.01 to 100 rather than 0 to 100. A log scale also reveals structure. An exponential decay y=y0e−t/τy = y_0 e^{-t/\tau} becomes a straight line on a log y-axis, because log⁡10y\log_{10} y falls linearly with tt.



What to remember

  • Label each axis with the quantity and its unit, and scale the data so the unit is true.
  • A legend lists only series plotted with label=.
  • Data coordinates follow the data; axes coordinates run from 0 to 1 across the plotting area.
  • On a linear axis f=(x−xmin⁡)/(xmax⁡−xmin⁡)f = (x - x_{\min})/(x_{\max} - x_{\min}); on a log axis apply the same rule to log⁡10\log_{10} values.
  • Log-axis limits must be positive, and exponentials plot as straight lines on a log y-axis.

Example: Annotating a capacitor discharge plot

A capacitor charged to 12.0 V discharges through a resistor with time constant τ=2.0\tau = 2.0 ms, so its voltage is V(t)=12.0 e−t/τV(t) = 12.0\,e^{-t/\tau} V. The array t holds sample times in seconds, from 0 to 0.010 s, and v holds voltages in volts. You start with this code:


Python
fig, ax = plt.subplots()
ax.plot(t, v, label="Measured")
ax.set_ylim(0, 12)


a) Label the time axis in milliseconds with ticks every 2 ms. What must you do to the data, and where do the ticks go?


A millisecond is one-thousandth of a second, so every time value must be multiplied by ________ before plotting. Plotting t * 1000 makes the last sample, 0.010 s, appear at ________ on the axis. Then label and tick the axis:

  • ax.plot(t * 1000, v, label="Measured") replaces the original plot call.
  • ax.set_xlabel("Time (ms)") and ax.set_ylabel("Voltage (V)") state each quantity and its unit.
  • ax.set_xlim(0, 10) and ax.set_xticks([0, 2, 4, 6, 8, 10]) give ticks every 2 ms.

The axis carries six ticks, at 0, 2, 4, 6, 8 and 10 ms. Changing only the label would leave the tick labels reading 0.000 to 0.010 under a label that says ms, a factor-of-1000 error.


b) Add an annotation whose arrow points at the curve at t=τt = \tau, with its text placed at axes coordinates (0.45, 0.70). Find the arrow's target and the text's position, both in data coordinates.


At t=τ=2.0t = \tau = 2.0 ms the exponent is −1-1, and e−1e^{-1} is ________, so


V(τ)=12.0 e−1=12.0×0.3679=4.41 VV(\tau) = 12.0\,e^{-1} = 12.0 \times 0.3679 = 4.41\ \text{V}


The arrow target is (2.0 ms, 4.41 V)(2.0\ \text{ms},\ 4.41\ \text{V}). After part a the time axis runs from 0 to 10 ms, and ax.set_ylim(0, 12) gives the voltage axis a span of ________. Inverting the axes-fraction rule, x=xmin⁡+fx(xmax⁡−xmin⁡)x = x_{\min} + f_x(x_{\max} - x_{\min}), gives


xtext=0+0.45×10=4.5 msytext=0+0.70×12=8.4 V\begin{aligned} x_{\text{text}} &= 0 + 0.45 \times 10 = 4.5\ \text{ms} \\ y_{\text{text}} &= 0 + 0.70 \times 12 = 8.4\ \text{V} \end{aligned}


The text sits at (4.5 ms, 8.4 V), above and to the right of the target. The curve at 4.5 ms is only 12.0 e−2.25=1.2612.0\,e^{-2.25} = 1.26 V, so the text is well clear of the data. The call is ax.annotate("t = τ", xy=(2.0, 4.41), xytext=(0.45, 0.70), textcoords="axes fraction", arrowprops={"arrowstyle": "->"}).


c) You switch the voltage axis to a log scale with limits 0.01 V to 100 V. Where does the annotated point now sit as a vertical axes fraction, does the text placement from part b still work, and what shape does the curve take?


Call ax.set_yscale("log") and ax.set_ylim(0.01, 100); the old lower limit of 0 is not allowed because a log axis cannot include zero. The axis spans log⁡10100−log⁡100.01=2−(−2)\log_{10} 100 - \log_{10} 0.01 = 2 - (-2), which is ________ decades. For the target, log⁡104.41\log_{10} 4.41 is ________, so


fy=0.644−(−2)4=2.6444=0.661f_y = \frac{0.644 - (-2)}{4} = \frac{2.644}{4} = 0.661


The point now sits at a vertical axes fraction of 0.661, up from 4.41/12=0.3684.41/12 = 0.368 on the linear axis. Because the text was placed in axes coordinates, it did not move: it is still at 0.70, only about 0.04 of the axis height above the point, so the arrow becomes short and nearly horizontal. Moving the text to (0.45, 0.85) restores a clear arrow.


On the log axis the decay is a straight line, because


log⁡10V=log⁡1012.0−tτln⁡10\log_{10} V = \log_{10} 12.0 - \frac{t}{\tau \ln 10}


falls at 1/(2.0×2.303)=0.2171/(2.0 \times 2.303) = 0.217 decades per millisecond. The last sample, 12.0 e−5=0.080912.0\,e^{-5} = 0.0809 V at 10 ms, stays above the 0.01 V lower limit, so the whole curve is visible.

Match each element of an annotated scientific plot with the job it does for a reader who is trying to interpret the figure without any other explanation.

Match each term
A.

Value printed beside a mark at a position along an axis

B.

One-line heading stating what the whole figure shows

C.

Key identifying which colour, line style or marker belongs to each data series

D.

Positions measured as fractions of the plotting area, from 0 to 1

E.

Text, often with an arrow, that points out one specific feature such as a peak

F.

Names the quantity along one axis and the unit of its numbers

Legend

Axes coordinates

Annotation

Tick label

Axis label

Title

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

When you place text on a plot, a position measured in the same units as the plotted values is said to be in coordinates. A position measured as a fraction of the plotting area is in axes coordinates, where the bottom edge of the plotting area is at and the top edge is at , whatever the axis limits are.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

You are preparing a scientific plot for a printed laboratory report. Match each formatting or export term to its meaning so that you can choose the appropriate setting.

Match each term
A.

A file representation that stores lines and text as geometric descriptions rather than only a pixel grid

B.

The intended width and height on the printed page

C.

The number of image pixels per inch at a specified printed size

D.

The size of text measured in points

Font size

Vector output

Physical dimensions

Raster resolution

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Extra Practice