[Tex/LaTex] pgfplots: relative node positioning in axis cs

nodespgfplotspositioning

I have got a file to plot with pgfplots. For convenience I'd like to define a measure in the plot. Unfortunately the relative positioning seems to give weird results. If I define the node coordinates manually everything works fine. According to the pgfplots-manual the sin- and cos-operators use degrees. Could you please tell me where my error is?

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usepackage{siunitx}

\pgfplotsset{compat=1.10}

\begin{document}

\pgfplotsset{cellmodel/.style={%
width=0.4\linewidth,
height=0.3\textheight,
axis lines=center,
axis equal image,
domain=0:800,
xmin= 0, xmax= 7,
ymin=-1.5, ymax=6.5,
restrict x to domain=0:7,
ticks=none,
}}

\begin{tikzpicture}
\def\angle{-30}
\begin{axis}[cellmodel]
\addplot[mark=x, mark options={solid}, draw=gray!80!black, dashed, thick] coordinates { 
        (0.0,0.5)
        (2.25,0.5)
        (4.5,4.397114317029974)
        (6.75,4.397114317029974)
};

% necessary nodes
\node (two) at (axis cs:2.25,0.5) {};
\node (thr) at (axis cs:4.5,4.397114317029974) {};

% relative nodes
% \node (mes2l)  at ($(two)+({cos(\angle)},{sin(\angle)})$) {test};     % <- doesn't give the correct coordinates
% \node (mes3l)  at ({$(thr)+({cos(\angle)},{sin(\angle)})$}) {test};
% \node (mes2l)  at ($(two)+(axis cs:{cos(\angle)},{sin(\angle)})$) {test};     % <- doesn't give the correct coordinates
% \node (mes3l)  at ({$(thr)+(axis cs:{cos(\angle)},{sin(\angle)})$}) {test};
\node (mes2l)  at (axis cs:3.116025404,0) {};                   % <- correct coordinates
\node (mes3l)  at (axis cs:5.366025404,3.897114317) {};
\draw[<->]  (mes2l.center) -- (mes3l.center) node [below right, midway]{$l$};
\end{axis}
\end{tikzpicture}

\end{document}

Best Answer

Might be easiest to just move the definition of the mes21 and mes31 nodes outside the axis, then they use the coordinate system of the tikzpicture rather than the axis. (I changed the angle to -30.)

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usepackage{siunitx}

\pgfplotsset{compat=1.10}

\begin{document}

\pgfplotsset{cellmodel/.style={%
width=0.4\linewidth,
height=0.3\textheight,
axis lines=center,
axis equal image,
domain=0:800,
xmin= 0, xmax= 7,
ymin=-1.5, ymax=6.5,
restrict x to domain=0:7,
ticks=none,
}}

\begin{tikzpicture}
\def\angle{-30}
\begin{axis}[cellmodel]
\addplot[mark=x, mark options={solid}, draw=gray!80!black, dashed, thick] coordinates { 
        (0.0,0.5)
        (2.25,0.5)
        (4.5,4.397114317029974)
        (6.75,4.397114317029974)
};

% necessary nodes
\coordinate (two) at (axis cs:2.25,0.5) {};
\coordinate (thr) at (axis cs:4.5,4.397114317029974) {};
\end{axis}

\def\scaling{0.4}
\coordinate (mes2l)  at ($(two)+\scaling*({cos(\angle)},{sin(\angle)})$);
\coordinate (mes3l)  at ($(thr)+\scaling*({cos(\angle)},{sin(\angle)})$);
\draw[<->]  (mes2l) -- (mes3l) node [below right, midway]{$l$};
\end{tikzpicture}

\end{document}