Blog

PGFPlots coordinates in LaTeX: a label that misses the curve

Inside a PGFPlots axis, a coordinate such as (7,9) is not always a point on the plotted scale. With the old default compatibility setting it is not, and a label that should sit near a curve can appear at the origin instead. This post works through the LaTeX example from a TeX Stack Exchange question asked on 27 November 2026, and the accepted fix.

The source is ordinary LaTeX: it compiles with a standard TeX distribution, and it is compatible with Overleaf.

The misplaced label

The minimal example is a Beamer frame with a dotted ray (y=(3/2)x) and a node at (7,9):

\addplot[samples=2,thin,black,dotted,domain=0:10] {x*(3/2)};
\path (7,9) node {$\mathit{MP}_x=\text{Undefined}$};

The ray is clipped by ymax=10, so its visible end is near the top of the frame. The point ((7,9)) should sit just below that end. Without a contemporary compat setting, the label does not go there.

Result

A Beamer slide with unmarked x and y axes and a thin dotted ray from the origin towards the top-right. The label MP_x = Undefined is not near the top of the ray. The letters MP_x are clipped at the left of the axis, and “= Undefined” sits just above the origin.

LaTeX source

\documentclass{beamer}

\usepackage{pgfplots}

\begin{document}
\begin{frame}
  \begin{figure}
    \begin{tikzpicture}
      \begin{axis}[
        ticks=none,
        axis x line=bottom,
        axis y line=left,
        xmin=0,xmax=10,
        ymin=0,ymax=10]
        \addplot[samples=2,thin,black,dotted,domain=0:10] {x*(3/2)};
        \path (7,9) node {$\mathit{MP}_x=\text{Undefined}$};
      \end{axis}
    \end{tikzpicture}
  \end{figure}
\end{frame}
\end{document}

Open in Lilia

This example is a complete document. Open it in Lilia to change it and compile it yourself, or download the PDF it produces: no account is needed for that.

Why (7,9) is not an axis point

In older PGFPlots, a bare coordinate inside axis is not read on the plot's scale: to place something at a data point, you had to write the axis cs: prefix. Since compatibility level 1.11, axis cs is the default coordinate system inside axis, so (7,9) means the data point ((7,9)). That behaviour is only switched on when the document asks for a compatibility level of 1.11 or later.

With no \pgfplotsset{compat=...}, PGFPlots keeps its historical default (and says so in the log: "running in backwards compatibility mode"), so (7,9) is not ((7,9)) on the plotted axes. In this example the label ends up at the origin, and the part of it that falls left of the axis is clipped.

The fix: a contemporary compat, or axis cs:

samcarter's accepted answer sets a current compatibility level. The answer uses \pgfplotsset{compat=newest}. A pinned contemporary version has the same effect for coordinates and will not change in a later PGFPlots release. The complete example below uses 1.18:

\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

The \path (7,9) node {…} line can stay as it is. The label now appears at axis point ((7,9)), just below the upper end of the dotted ray.

Result

The same Beamer slide and dotted ray, after setting pgfplots compat to 1.18. The full label MP_x = Undefined is centred on the axis point (7,9), near the top of the visible ray: the ray passes through MP_x, just below where the line is clipped by the top of the axis.

LaTeX source

\documentclass{beamer}

\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
\begin{frame}
  \begin{figure}
    \begin{tikzpicture}
      \begin{axis}[
        ticks=none,
        axis x line=bottom,
        axis y line=left,
        xmin=0,xmax=10,
        ymin=0,ymax=10]
        \addplot[samples=2,thin,black,dotted,domain=0:10] {x*(3/2)};
        \path (7,9) node {$\mathit{MP}_x=\text{Undefined}$};
      \end{axis}
    \end{tikzpicture}
  \end{figure}
\end{frame}
\end{document}

Open in Lilia

This example is a complete document. Open it in Lilia to change it and compile it yourself, or download the PDF it produces: no account is needed for that.

If you need to keep an older compat value, write the point in the axis coordinate system explicitly:

\path (axis cs:7,9) node {$\mathit{MP}_x=\text{Undefined}$};

\text{…} comes from amsmath, which Beamer loads on its own. In an article document you would add \usepackage{amsmath}.

Doing it in Lilia

Lilia is a browser editor where a paper is a sequence of blocks with LaTeX underneath. The examples above are complete documents.

Open the example. Use Open and edit in Lilia on the example's tab. You can move the node, change compat, or try axis cs: and compile the PDF there. The same source can also be pasted with Paste LaTeX from the command palette (the ? button in the top bar), or imported as a .tex file or an Overleaf zip from Import / Export.

Check that it compiles. Click the shield in the left rail (Validate), then Validate now. Lilia compiles the document with a real TeX engine. For the misplaced example, the check also lists PGFPlots' own warning, "running in backwards compatibility mode": the clue that compat is missing. Each copy is a Beamer deck that opens with a title slide; the next slide has the plot, with the label where the Result tab shows it.

Hand it on. Export → LaTeX gives a single .tex or a project .zip (flat or Overleaf-style). The compat line goes with you as ordinary LaTeX, so a co-author can compile it on Overleaf or in a local TeX distribution.

Credit

This post follows the question Coordinates in pgfplots, asked by Patricio on TeX Stack Exchange on 27 November 2026. The compat fix is from samcarter's accepted answer. Both are used here under CC BY-SA.

Summary

  • A bare (x,y) inside axis is an axis data point only when compat is 1.11 or newer.
  • Without that setting, a label can compile cleanly and still sit in the wrong place, here at the origin.
  • Set \pgfplotsset{compat=1.18} (or another contemporary version), or write (axis cs:x,y).

If you'd like to try this without installing anything, Lilia's Free plan includes 3 documents, every export format and the compile check: liliaeditor.com.