9

This issue has been driving me crazy for the past 10-20h. I have a group plot (pgfplots) where I have 2 plots one under another. I'd like to draw a vertical line (e.g. a helpline at x=150e-6) that would go through all of them.

When drawing inside the axis or rather nextgroupplot environment I can use something like this: \draw[thin] (axis cs:150e-6,\pgfkeysvalueof{/pgfplots/ymin}) -- (axis cs:150e-6,\pgfkeysvalueof{/pgfplots/ymax}); but this allows me to draw only on one of the subplots. If I go outside the axis environment I am able to draw on the entire {tikzpicture}, but I can't use the axis reference.

\begin{figure*}[h]
\centering
\begin{tikzpicture}

\begin{groupplot}[
      group style = {group size=1 by 2, x descriptions at=edge bottom, vertical sep=0.2cm},
      ytick={0, 1.8},
      ymin=0,
      ymax=3,
      xmin=0,
      xmax=550e-6,
      change x base=true,
      x SI prefix=micro]

\nextgroupplot
\addplot table [x index = {0}, y index = {1}, col sep=comma] {plots/plot1reduced.csv};

\nextgroupplot[x unit=s]
\addplot table [x index = {0}, y index = {3}, col sep=comma] {plots/plot1reduced.csv};

\draw[thin] (axis cs:150e-6,\pgfkeysvalueof{/pgfplots/ymin}) -- (axis cs:150e-6,\pgfkeysvalueof{/pgfplots/ymax});

\end{groupplot}
\end{tikzpicture}
\caption{Case 1}
\label{fig:case1plot}
\end{figure*}
  • Welcome to TeX.SX! It is always best if the example you provide is directly compilable for us. In this it obviously isn't, because we don't have the data files, the preamble with packages and libraries are missing. – Torbjørn T. Feb 25 '15 at 11:22
  • @TorbjørnT. Sorry about that. I'm new and I wasn't sure if the TeX compiling a special feature or something normal. I'll make sure to post compilable TeX in the future. – Wojciech Feb 25 '15 at 11:32
  • No worries. In some cases a proper minimal working example (MWE) may be absolutely necessary to be able to find a solution, but sometimes it's just about removing obstacles for those trying to help by making it easy to test the code at hand. 'Helping us help you', as some would say. – Torbjørn T. Feb 25 '15 at 11:42
11

You could add a \coordinate in the top and bottom groupplot, and draw the line afterwards using those as a reference.

\documentclass{standalone}

\usepackage{pgfplots}
\usepgfplotslibrary{groupplots,units}
\begin{document}
\begin{tikzpicture}

\begin{groupplot}[
      group style = {group size=1 by 2, x descriptions at=edge bottom, vertical sep=0.2cm},
      ytick={0, 1.8},
      ymin=-3,
      ymax=3,
      xmin=0,
      xmax=3]

\nextgroupplot
\addplot {x};
\coordinate (top) at (axis cs:1,\pgfkeysvalueof{/pgfplots/ymax});

\nextgroupplot[x unit=s]
\addplot {-x};

\coordinate (bot) at (axis cs:1,\pgfkeysvalueof{/pgfplots/ymin});

\end{groupplot}
\draw [thin] (top) -- (bot);
\end{tikzpicture}
\end{document}

enter image description here

4

You can do it with

\draw[thick,red] (group c1r1.north) -- (group c1r2.south);

Code:

\documentclass{standalone}

\usepackage{pgfplots}
\usepgfplotslibrary{groupplots,units}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}

\begin{groupplot}[
      group style = {group size=1 by 2, x descriptions at=edge bottom, vertical sep=0.2cm},
      ytick={0, 1.8},
      ymin=-3,
      ymax=3,
      xmin=0,
      xmax=3]

\nextgroupplot
\addplot {x};

\nextgroupplot[x unit=s]
\addplot {-x};

\end{groupplot}
\draw[thick,red]
(group c1r1.north) -- (group c1r2.south);
\draw[thick,blue]
([xshift=-11mm]group c1r1.north) -- ([xshift=-11mm]group c1r2.south);
\end{tikzpicture}
\end{document}

enter image description here

  • Not exactly what I was looking for. You're proposing an [xshift=-11mm] while I was looking for something that would refer to the X axis value i.e. draw a line at a certain x value. Looking for the proper [xshift=] for each plot would be a nightmare. – Wojciech Feb 26 '15 at 2:07

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.