[Tex/LaTex] Draw line between two plots

pgfplots

I am trying to draw a line between points of two plots as shown in the picture (the blue line) but without luck. It is with tikzpicture and pgfplots. Similar to:

\begin{tikzpicture}
\begin{axis}
  \addplot coordinates { (1,2) (2,3) };
  \addplot coordinates { (1,4) (2,6) };
\end{axis}
\end{tikzpicture}

I did try adding nodes to \addplot but they seem to be located at (0,0) regardless of settings.

Any suggestions?

Best Answer

The pgfplots package introduces an own coordinate system that allows you to use the diagram's coordinates with normal tikZ drawing commands. Just put an axis cs: before your coordinates as in

\draw (axis cs:1,0) -- (axis cs:2,0);

The following code below shows your code expanded with a line drawn from the points (2,3) to (2,6):

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}
    \addplot coordinates { (1,2) (2,3) };
    \addplot coordinates { (1,4) (2,6) };
    \draw (axis cs:2,3) -- node[left]{Text} (axis cs:2,6);
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here