I have an interesting problem. I am trying to create two graphs using the groupplots environment, side-by-side, that show different sets of data elements with different legend entries and different markers. I'd like to combine their [disjoint] legend entries into a single common legend.
For example:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{groupplot}[
legend to name=MyLegend,
legend columns=3,
group style={group size=2 by 3,ylabels at=edge left},
ylabel style={text height=0.02\textwidth,inner ysep=0pt},
height=0.475\linewidth,width=0.475\linewidth,/tikz/font=\small]
\nextgroupplot
\addplot [color=black!90,mark=x] coordinates {
(1, 10698) (2, 10853) (4, 17151) (8, 22366)
(12,28016) (16,32345) (20,36076) (24,40908)
};
\addlegendentry{ABC}
\nextgroupplot
\addplot[color=black!75,mark=*] coordinates {
(1, 17500) (2, 14600) (4, 25300) (8, 38800)
(12,49100) (16,58800) (20,67400) (24,75000)
};
\addlegendentry{DEF}
\end{groupplot}
\end{tikzpicture}
\\
\ref{MyLegend}
\end{center}
\end{document}
I would like the legend to both display ABC and DEF, along with their respective markers.