I'm trying to display a few plots using pgfplots and groupplots using the following example. I take the titles of each plot from a different data file than the data itself. The data appear to be plotted in the correct order, as the manual specifies, but the titles aren't applied to the correct plots (for example, "0: 0 - 5" should be in the upper right). It seems as if the #1 argument is one greater than it should be, but then the correct data column is loaded. Why are the titles not ordered the same way as the data?
\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepgfplotslibrary{groupplots}
\pgfplotsset{
compat=newest,
every minor tick={very thin, LightGray},
minor tick num=4,
enlargelimits=0.02
}
\pgfplotstableread{
Time {Data 0} {Data 1} {Data 2} {Data 3}
0 7.0 2.3 0.3 1.4
1 6.0 3.6 1.2 2.7
2 5.0 4.8 3.0 3.5
3 4.0 5.9 3.9 7.3
4 3.0 7.3 4.3 6.0
5 2.0 6.5 5.5 7.2
6 1.0 8.9 7.0 8.4
}\datatable
\pgfplotstableread{
Min Max
0 5
6 10
11 15
20 25
}\groupmeta
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
xlabel={Time},
ylabel={Amplitude},
every axis title shift=0,
% Style list for each plot in order
cycle list={
{only marks, mark=o}
},
group style={group size=2 by 2,
xlabels at=edge bottom,
ylabels at=edge left}]
\pgfplotsinvokeforeach{0,1,2,3}{
% Read in title
\pgfplotstablegetelem{#1}{Min}\of{\groupmeta}
\edef\min{\pgfplotsretval}
\pgfplotstablegetelem{#1}{Max}\of{\groupmeta}
\edef\max{\pgfplotsretval}
% Just to test which element this is...
\def\test{#1}
\nextgroupplot[title=\(\test:\ \min - \max\)]
% Data
\addplot+ table[x index=0, y=Data #1] {\datatable};
}
\end{groupplot}
% Title placement
\node (dummytitle) at ($(group c1r1.north)!0.5!(group c2r1.north)$)
[above]{};
\node (title) at (dummytitle.north)
[above, yshift=\pgfkeysvalueof{/pgfplots/every axis title shift}]
{Experimental Data};
\end{tikzpicture}
\end{document}

