# Incorrect relative node position in axis environment

I would like to draw a path in a graph plotted with pgfplots, using relative (++) coordinates. The following code compiles without any error, but the points are not at the desired position:

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

\begin{document}

\begin{tikzpicture}
\begin{axis}
\addplot{x^2};
\draw (1,2) --++ (0,1) --++ (1,0) --++ (0,1); % This should result in a staircase
\end{axis}
\end{tikzpicture}

\end{document}


Any idea of what causes this problem?

• I can't answer the question about the cause of the problem, but you might like to make the staircase with "const plot" instead. For example, try adding a new line: \addplot [red,const plot] {x^2}; – Thruston Jan 15 '17 at 14:20
• Thank you, but I am not particularly interested in plotting a staircase: this is just an simple example of a path based on relative coordinates. – Tobard Jan 15 '17 at 14:27

## 1 Answer

As you can find in the PGFPlots manual in 4.17.1 on page 349 (v1.14) you need to use axis direction cs to make relative coordinates work.

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
% use this compat' level or higher so you don't need to state axis cs:'
% at the coordinates
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot{x^2};
\draw [red,very thick] (1,2)
-- ++(axis direction cs:0,1)
-- ++(axis direction cs:1,0)
-- ++(axis direction cs:0,1)
;
\end{axis}
\end{tikzpicture}
\end{document}


• For your information: Besides accepting the answer you could also upvote it by clicking on the the 'up' arrow above the answer's score. – Stefan Pinnow Jan 15 '17 at 15:30
• axis direction cs or axis description cs ?? Your code differs from your description. – Thruston Jan 15 '17 at 18:04
• @Thruston, sorry, my fault. Corrected my "typo". Thanks for the hint. – Stefan Pinnow Jan 15 '17 at 18:06