# Placing node at path using midway in pgfplots

I thought my problem would have been possibly answered anywhere here, but I could not get it to work. Questions I consider linked to mine but which weren´t able to solve my issue are node placement problem and pgfplots: placing node on a specific x-position.

I want to make an annotation to a graph drawn using pgfplots (actually, its inside a groupplots-environment). I tried so using the PGF-command draw[<-> (pos a) node [midway,...] -- (pos b). However, the node did not get placed midways, but in the middle of nowhere. This is not true for below and above. However, the same thing happens when I used near end or pos=???.

I worked around this issue just placing a node manually at the place where I want it. However, I don´t find this very satisfactory. Feel free to have a look at the MWE below.

\documentclass{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\begin{document}
\begin{tikzpicture}
\begin{axis}[{hide y axis,
axis x line=middle,
height=3cm, width=10cm,
xmin=-22.5, xmax=83,
samples=200,
xtick={-20, 0,20, 40, 60, 80}}]

% % % % % The erroneous part:
% 1.:
\draw[<->,green!70!black,thick] (axis cs:40,0)
node[midway, above,font=\scriptsize] {$\varphi_1$} % This SHOULD work, but doesn´t
-- (axis cs:50,0);

% 2.:
\node[font=\scriptsize,green!70!black] at (axis cs:45,.3) {$\varphi_1$}; %This does work

\end{axis}

\end{tikzpicture}
\end{document}

• I also know it would be nice to calculate the intersection. I tried to understand the answers here and here, but I couldn´t. Maybe its overkill for a little bit of sine... Apr 28 '14 at 22:07
• You need \draw[<->,green!70!black,thick] (axis cs:40,0) -- (axis cs:50,0) node[midway, above,font=\scriptsize] {$\varphi_1$}; Apr 28 '14 at 22:18

You need to place the node either at the end of the path:

\draw[<->,green!70!black,thick]
(axis cs:40,0) -- (axis cs:50,0) node[midway, above,font=\scriptsize] {$\varphi_1$};

or after the to part:

\draw[<->,green!70!black,thick]
(axis cs:40,0) -- node[midway, above,font=\scriptsize] {$\varphi_1$} (axis cs:50,0);

A complete example:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
hide y axis,
axis x line=middle,
height=3cm, width=10cm,
xmin=-22.5, xmax=83,
samples=200,
xtick={-20, 0,20, 40, 60, 80}
]
(axis cs:40,0) -- node[midway, above,font=\scriptsize] {$\varphi_1$} (axis cs:50,0);
(axis cs:10,0) -- (axis cs:20,0) node[midway, above,font=\scriptsize] {$\varphi_2$};