2

I use a "parent" tikzpicture to realize a more flexible positioning of pgfplots than what is possible with groupplots i.e. I put the pgfplots in nodes as in the following MWE:

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{positioning,calc}
\pgfplotsset{every axis/.append style={width=5cm}}

%\tikzstyle{every picture}+=[remember picture,overlay]

\begin{document}
\begin{tikzpicture}
\node (TL) {% Plot 1
    \begin{tikzpicture}
    \begin{axis}
    \addplot coordinates { (-5,100) (115,10) };
    \coordinate (C) at (axis cs: 0,0);
    \end{axis}
    \end{tikzpicture}
};
\node[right=1cm of TL] (TR) {% Plot 2
    \begin{tikzpicture}
    \begin{axis}
    \addplot coordinates { (-5,-120) (15,100) };
    \coordinate (D) at (axis cs: 0,0);
    \end{axis}
    \end{tikzpicture}
};
\node[anchor=north] (B) at ($(TL.south)!0.5!(TR.south)$) {% Plot 3
    \begin{tikzpicture}
    \begin{axis}
    \addplot coordinates { (-5,100) (115,100) };
    \end{axis}
    \end{tikzpicture}
};
\end{tikzpicture}
\end{document}

enter image description here

Is there a way to connect the coordinates (C) and (D) with a line? I tried the remember picture, overlay option, but this did not work and the position of the figure was on the top left corner of the page.

  • 1
    Nesting tikzpictures is never a good way to go. In particular, I would try the groupplots library of pgfplots for this type of applications: at the end of the day, setting options properly you can customize more or less as you want the layout. – Claudio Fiandrino Jul 13 '16 at 6:55
2

If you add the remember picture option you can then access these nodes in a different tikzpicture environment:

enter image description here

Notes:

  • This is just to show how to use remember picture option and then connect the nodes. I am not recommending nesting tikzpicture environments.

Code:

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{positioning,calc}
\pgfplotsset{every axis/.append style={width=5cm}}

%\tikzstyle{every picture}+=[remember picture,overlay]

\begin{document}
\begin{tikzpicture}[remember picture]
\node (TL) {% Plot 1
    \begin{tikzpicture}
    \begin{axis}
    \addplot coordinates { (-5,100) (115,10) };
    \coordinate (C) at (axis cs: 0,0);
    \end{axis}
    \end{tikzpicture}
};
\node[right=1cm of TL] (TR) {% Plot 2
    \begin{tikzpicture}[remember picture]
    \begin{axis}
    \addplot coordinates { (-5,-120) (15,100) };
    \coordinate (D) at (axis cs: 0,0);
    \end{axis}
    \end{tikzpicture}
};
\node[anchor=north] (B) at ($(TL.south)!0.5!(TR.south)$) {% Plot 3
    \begin{tikzpicture}
    \begin{axis}
    \addplot coordinates { (-5,100) (115,100) };
    \end{axis}
    \end{tikzpicture}
};
\end{tikzpicture}
%
\begin{tikzpicture}[remember picture,overlay]
\draw [thick, red] (C) -- (D);
\end{tikzpicture}%
\end{document}
  • Why not give a solution with groupplots or even use separate tikzpicture environments? – Alenanno Jul 13 '16 at 9:47
  • 1
    @Alenanno: As the main question here was about connection tikz nodes, I did not fix that issue but just pointed it out in the notes. – Peter Grill Jul 13 '16 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.