0

My question is similar to this one: Draw arrows between nodes with tikz

I want to draw several lines with arrow heads using relative coordinates. I expect the command \draw (axis cs:0,0) edge[->] ++(axis direction cs:-2,0) edge[->] ++(axis direction cs:0,1); to result in the following plot (left), but get the one on the right.

enter image description here

However, the coordinates are not moved from the origin, although ++ is used. MWE:

\documentclass[a4paper]{article} 
\usepackage{pgfplots}

\begin{document} \begin{tikzpicture}% \begin{axis}[title={want},axis lines=middle,xmin=-3, xmax=1, ymin=-2, ymax=3,] % This is the result I want \draw[green,->] (axis cs:0,0) -- ++(axis direction cs:-2,0); \draw[green,->] (axis cs:-2,0) -- ++(axis direction cs:0,1); \end{axis} \begin{axis}[xshift=7cm, axis lines=middle, title={got},xmin=-3, xmax=1, ymin=-2, ymax=3,] % I want to use multiple relative coordinates in one command as in the following: \draw[red] (axis cs:0,0) edge[->] ++(axis direction cs:-2,0) edge[->] ++(axis direction cs:0,1); \end{axis} \end{tikzpicture}% \end{document}

Manuel Schmidt
  • 3,537
  • 1
  • 19
  • 33

1 Answers1

2

Always set compat level when using PGFPlots. Do not write axis cs: - it is the default coordinate system.

edge starts a new path, so the ++ will not help anything. It is normal TikZ behaviour - not just PGFPlots. I do not know what you are trying to achieve, so can not say what the best way is. It could be an \addplot a \foreach loop (or PGFPlot friendly versions). -or simply give up on the idea of not specifying the start point of the next arrow (like in the link you give).

Here is one way with just the two points you specify:

\documentclass[tikz, border=1cm]{standalone} 
\usepackage{pgfplots} 
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines=middle, xmin=-3, xmax=1, ymin=-2, ymax=3,]
\draw[red, thick, ->] (0,0) edge +(axis direction cs:-2,0) \pgfextra{\pgfgetlastxy{\macrox}{\macroy}} (\macrox,\macroy) -- +(axis direction cs:0,1);
\end{axis}
\end{tikzpicture}
\end{document}

Two arrows in a coordinate system