i am using pgfplots to plot some two-dimensional data that depend on three parameters. I'm trying to use a box at the top of the plot that contains the fixed parameter (see MWE).
I want the box to be centered at the x-axis, but this fails and the box is shifted. How can this be fixed such that the box is centered?
\documentclass[]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[sb]{libertine}
\usepackage[T1]{eulervm}
\usepackage{pgfplots}\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}[remember picture]
\begin{axis}[
xlabel=Speed factor $SF$,
ylabel=Time,
x dir = reverse,
legend pos=outer north east,
xtick = data,
]
\addplot table [y=T3, x=SF]{data.dat};
\addlegendentry{PF = 3\phantom{.0}}
\addplot table [y=T25, x=SF]{data.dat};
\addlegendentry{PF = 2.5}
\addplot table [y=T15, x=SF]{data.dat};
\addlegendentry{PF = 1.5}
\end{axis}
\node [draw,fill=white, anchor=center] at (rel axis cs: -0.5,1.05) {$TF=15$};
\end{tikzpicture}
\end{document}
Content of data.dat:
SF T3 T25 T15
1 183 214 341
0.9 197 232 370
0.8 239 282 450
0.7 267 314 504
Best Answer
In your code you are using
rel axis cs:
outside theaxis
environment which should not work (as expected). But you had the right idea to use a "relative" coordinate system to position the box. I suggest usingaxis description cs:
to position it, because this is independent ofxdir
value.For sure, both (
rel axis cs:
andaxis description cs:
) are better than the normalaxis cs:
because this always is dependent on the data you show. I personally only use it if I have to annotate a point in that (shown) coordinate system, but not for "general" annotations.(I am sure there was already a question about this topic in the near past, but couldn't find it after a quick search.)