This answer showed how to make overlay drawings with nodes defined in previous plots using TikZ
. However, that solution (ie. adding cell picture=if necessary
to the axis) does not work with groupplots
.
If I do not use the option, I get the same problem that was solved by the answer linked to above, and even worse results for the second plot:
Adding the option to the \nextgroupplot
commands (which are equivalent the axis statements) solves part of the problem (the arrows point to the nodes) but it breaks alignment of the plots:
Question: how can I make overlay drawings using nodes that have been defined in previous plots by groupplots
?
MWE
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary[pgfplots.groupplots]
\begin{document}
\begin{figure}
\begin{tikzpicture}[remember picture]
\begin{groupplot}[group style={group size=2 by 1},ymin=0,ymax=3]
\nextgroupplot[cell picture=if necessary] \addplot {1};
\node [fill,red,circle,draw,label={above:A}] (a) at (axis cs:-4,2) {};
\nextgroupplot[cell picture=if necessary] \addplot {2};
\node [fill,blue,circle,draw,label={above:B}] (b) at (axis cs:4,1) {};
\end{groupplot}
\end{tikzpicture}
\caption{A \texttt{groupplots} plot}
\end{figure}
This arrow should point to A
\tikz[remember picture,overlay] \draw[red,->] (0,0) -- (a);
and this arrow should point to B
\tikz[remember picture,overlay] \draw[red,->] (0,0) -- (b);
\end{document}
pgfplots
layer andgroupplots
. Instead, you should try the "manual" alignment (there is an example of whatgroupplots
do in its section) and see if the problem persists. Perhaps that could help?