# pgfplots 3d cylindrical coordinate system

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.

## 2 Answers

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}


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}


• Although I was not aware of the data cs key, I have clarified my question above. Yet, I will make use of data cs! – Markus Mar 31 '14 at 16:06
• @Markus I added some code that perhaps gets you started on a 3D polar axes system :) – hugovdberg Mar 31 '14 at 19:34
• This works nicely. Is it possible to plot the cs in a different plane than x,y? I can manipulate the view to get what I want, yet it could make things a bit easier... – Markus Mar 31 '14 at 20:56
• You mean you want the polaraxis at an arbitrary z height? That could simply be accomplished by changing the \addplot commands to \addplot3 and add a z component. Or do you want the polaraxis at an angle with x,y? In that case you'll have to do some math to calculate the coordinates, but it should be possible to do so. If you simply want to look at the plot from a different angle you could also try the view option to the axis environment. – hugovdberg Mar 31 '14 at 21:45
• According to this answer, one can supply y domain=0:0 to specify a line plot instead of a mesh. This gets rid of the 'back connection' from the end back to the start of the plot, see here. – Hans Lollo Jul 10 at 11:21

run with xelatex or latex->dvisps->ps2pdf

\documentclass[pstricks]{standalone}
\usepackage{pst-solides3d}

\begin{document}
\begin{pspicture}(-3,-1)(3,4)
\psset{lightsrc=80 10 30,viewpoint=100 20 20 rtp2xyz,Decran=50}
\defFunction[algebraic]{FIII}(t)
{t^1.1*sin(15*t)}
{t^1.1*cos(15*t)}
{1.5*t}
\psSolid[object=courbe,range=0 4,ngrid=360 6,function=FIII,hue=0.2 0.3,linewidth=0.1pt,r=0.1]
\end{pspicture}

\end{document}


• I do like the pstricks style, but would rather stay within tikz/pgfplots. I have updated the question above as well. – Markus Mar 31 '14 at 16:04