3

I would like to annotate plots produced with pgfplots in such a way that:

  1. The baseline of the annotation is aligned with the baseline of the x-axis label.
  2. The left margin of the annotation is aligned with the leftmost extent of the y-axis label.

The following example has been manually tweaked to approximately achieve this effect, but I would like it to be more accurate and not want to have to do this manually for every plot.

\documentclass[border=5mm]{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=0.0,xmax=1.0,ymin=0.0,ymax=1.0,xlabel=$x$,ylabel=$y$,clip=false]
  \addplot[color=red] table {
    0.1 0.9
    0.9 0.2
  };  
\node[anchor=west] at (axis cs:-0.15,-0.1) {Hello};  
\end{axis}
\end{tikzpicture}
\end{document}

I assume that at least 1. should be easily achieved if I could access the values used by pgfplots for placing the x-axis label. (I've looked through the pgfplots manual but could not find any information.)

I assume 2. is hard to do because we need to know not just the position of the label, but also its height, so I'm willing to settle for something that is approximate (but not manual).

4

I think that's what you want alignment with outer bounding box of your axis

\documentclass[border=5mm]{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[name=s,xmin=0.0,xmax=1.0,ymin=0.0,ymax=1.0,xlabel=$x$,ylabel=$y$,clip=false]
  \addplot[color=red] table {
    0.1 0.9
    0.9 0.2
  };  

\end{axis}
\node[anchor=south west] at (s.outer south west) {Hello}; 
\end{tikzpicture}
\end{document}

enter image description here

1

salim bou's answer is probably more convenient, here's a more manual way. Some adjustment to take the inner/outer sep of various nodes into account might be needed.

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=0.0,xmax=1.0,ymin=0.0,ymax=1.0,xlabel=$x$,ylabel=$y$,
every axis x label/.append style={alias=thexlabel},
every axis y label/.append style={alias=theylabel}]
  \addplot[color=red] table {
    0.1 0.9
    0.9 0.2
  };  
\end{axis}
\node[anchor=base west] (h) at (theylabel.north |- thexlabel.base) {Hello};
\end{tikzpicture}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.