# Automatically label groupplots (A), (B), (C),

Is there a way to automatically label a set of groupplots from the pgfplots package (A), (B), (C), ...?

\documentclass[margin=2pt]{standalone}

\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.8}

\begin{document}
\begin{tikzpicture}[shorten >=4pt,shorten <=4pt]
\begin{groupplot}[group style={group size=2 by 2,vertical sep=15mm},
height=3.5cm,width=3.5cm,/tikz/font=\small]
\nextgroupplot[title=(A)]
\nextgroupplot[title=(B)]
\nextgroupplot[title=(C)]
\nextgroupplot[title=(D)]
\end{groupplot}
\end{tikzpicture}
\end{document}


-

The groupplots library keeps the value of the current plot in the \pgfplots@group@current@plot count. So you can create the titles automatically using the alphalph package and the following style:

\makeatletter
\pgfplotsset{
auto title/.style={
title=(\AlphAlph{\pgfplots@group@current@plot})
}
}
\makeatother


Then you just add auto title to the axis options (or to the \nextgroupplot options), and you'll get the desired result:

\documentclass[margin=2pt]{standalone}

\usepackage{alphalph}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.8}

\makeatletter
\pgfplotsset{
auto title/.style={
title=(\AlphAlph{\pgfplots@group@current@plot})
}
}
\makeatother

\begin{document}
\begin{tikzpicture}[shorten >=4pt,shorten <=4pt]
\begin{groupplot}[group style={group size=2 by 2,vertical sep=15mm},
height=3.5cm,width=3.5cm,/tikz/font=\small, auto title]
\nextgroupplot
\nextgroupplot
\nextgroupplot
\nextgroupplot
\end{groupplot}
\end{tikzpicture}
\end{document}

-

There is still something I'm not quite solving properly, though this gives the desired result. As I would have wanted it to work, you would use \startaddplot for your first plot and \nextaddplot for subsequent plots.

But what happened is that the counter I used is somehow lagging in its step. So the crass fix I had to apply was initializing the counter to -1 instead of the expected value of 0, and also require you to issue a \noaddplot when you are done, to retroactively step the counter for the final plot.

I'm sure someone like egreg will chime in to tell me why my counter isn't keeping up.

\documentclass[margin=2pt]{standalone}

\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.8}
\newcounter{plotno}
\global\setcounter{plotno}{-1}%
}
\global\stepcounter{plotno}%
\nextgroupplot[title=(\Alph{plotno})]%
}
\begin{document}
\begin{tikzpicture}[shorten >=4pt,shorten <=4pt]
\begin{groupplot}[group style={group size=2 by 2,vertical sep=15mm},
height=3.5cm,width=3.5cm,/tikz/font=\small]