[Tex/LaTex] pgfplots 3d cylindrical coordinate system

3dpgfplotstikz-pgf

I am trying to plot a cylindrical coordinate system using pgfplots. The idea would be to plot the r,theta plane similar to what polaraxis provides, see here. I don't know how to translate something like this into a 3D environment.

Is there an easy way to plot a custom coordinate system within the current 3D axis?

UPDATE: I may not have been precise enough. I am specifically interested in plotting the coordinate/axis system, i.e. the r,theta grid in a 3D plot.

Best Answer

You can use the data cs key to set the coordinate system in which the data is interpreted. This works perfectly fine for 3D plots as well, supplying a third coordinate automatically acts as a cylindrical projection. See also section 4.24 Transforming Coordinate Systems of the pgfplots manual (v1.10).

\documentclass{article}

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

\begin{document}
  \begin{tikzpicture}
    \begin{axis}
      \addplot3+[data cs=polarrad,domain=0:2*pi] (\x,1,2*\x);
    \end{axis}
  \end{tikzpicture}
\end{document}

enter image description here


Update: Added a faked 3D polaraxis, this could definitely use some improvement, but might get you started. A better solution would apply the style of the "polar axis" somewhat nicer, and currently the labels are clipped, also the radius is fixed, that should probably be somehow dependent on the plotted data, but I don't have time to delve into this that deep at the moment.

I also changed the data cs to polar because I didn't get the foreach \thet to work with fractions of pi.

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usepgfplotslibrary{polar}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
      axis x line=middle,
      axis y line=middle,
      axis z line=middle,
      ytick=\empty,
      data cs=polar,
      ]
      \foreach \r in {0,0.25,...,1.25} {
        \addplot+[domain=0:360,mark=none,black,samples=200, smooth] (\x, \r);
      }
      \foreach \thet in {0,30,...,330} {
        % some trickery to get the label expanded
        \edef\doplot{\noexpand\addplot+[domain=0:1.3,mark=none,black] (\thet, \noexpand\x) node[pos=1.2]  {\thet};}
        \doplot
      }
      \addplot3+[domain=0:360] (\x,1,2*\x);
    \end{axis}
  \end{tikzpicture}
\end{document}

enter image description here

Related Question