# Cylinder is clipped in z domain

I'm trying to render a circular cylinder, mathematically defined as $y^2+z^2=r^2, x\in [0,5]$.

Here the MWE:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xlabel=$x$,ylabel=$y$, zlabel={$z$},
xmin = 0, xmax=5,
ymin=-2, ymax=2,
zmin=-2, zmax=2]
domain=0:5,z buffer=sort,
opacity=0.5] (x, {sin(deg(y))}, {cos(deg(y))});
\end{axis}
\end{tikzpicture}

\end{document}


But the shape of the cylinder got clipped somewhere:

• Unrelated: You must always set compat level (version) when using PGFPlot. Jan 24, 2022 at 15:04

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xlabel=$x$,ylabel=$y$, zlabel={$z$},
xmin = 0, xmax=5,
ymin=-2, ymax=2,
zmin=-2, zmax=2]
surf,
gray,
samples=2,
samples y=10,
domain=0:4,
y domain=0:2*pi,
z buffer=sort,
opacity=0.5,
] (x, {sin(deg(y))}, {cos(deg(y))});
\end{axis}
\end{tikzpicture}
\end{document}


You can use 3dtools

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc,3dtools}% https://github.com/marmotghost/tikz-3dtools
\begin{document}
\begin{tikzpicture}[3d/install view={phi=30,theta=70,psi=0},declare function={r=2;h=5;}]
\path[3d/record physical components]
(1,0,0) coordinate (ez')
(0,1,0) coordinate (ex')
(0,0,1) coordinate (ey');
\begin{scope}[x={(ex')},y={(ey')},z={(ez')}]
\pic{3d/frustum={r=r,R=r,h=h}};
\end{scope}
\draw[3d/hidden] (0,0,-r) -- (0,0,r) (0,0,0) -- (h,0,0) ;
\node[left] (O) at  (0,0,0) {$O$};
\draw[3d/visible, - latex] (h,0,0) -- (h+ 2,0,0) node[right]{$x$};
\draw[3d/visible, - latex] (0,0,r) -- (0,0,r+1) node[above]{$z$};
\draw[3d/hidden, - latex] (0,0,0) -- (0,r+1,0) node[above]{$y$};
\end{tikzpicture}
\end{document}


I use geometric transformations.

// copy to http://asymptote.ualberta.ca/ and click Run
unitsize(1cm);
import three;
currentprojection=orthographic(2,2,1,zoom=.8);
real r=1.5, h=5;
transform3 t=rotate(90,Y)*scale(r,r,h);
surface c=t*unitcylinder;
draw(c,yellow+opacity(.7));

draw(Label("$x$",EndPoint),O--(h+3)*X,Arrow3);
draw(Label("$y$",EndPoint),O--(r+1)*Y,Arrow3);
draw(Label("$z$",EndPoint),O--(r+1)*Z,Arrow3);