[Tex/LaTex] drawing lines using polar axis coordinate system in pgfplots

pgfplotstikz-pgf

I would like to draw arrows with polar axis notation in a pgfplots figure that has Cartesian axes with the draw command:

\draw[->] (polar axis cs:radius=1, angle=30) -- (polar axis cs:radius=2, angle=30);

I could not find any way to do something like this in the documentation. Are polar coordinates supported in the axis environment?

Best Answer

As a simple workaround you could calculate the coordinates with a bit of trigonometry, which can be put in a macro. Note that with compat=1.11 or newer axis cs is the default coordinate system. If you have compat=1.10 or older you need to use (axis cs:\rtheta{1}{30}).

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\newcommand\rtheta[2]{{#1*cos(#2)},{#1*sin(#2)}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines=middle,ymin=-1,ymax=1,xmin=-1,xmax=1]
\draw (\rtheta{0}{0}) -- (\rtheta{1}{30}) -- (\rtheta{1}{120});
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here