1

Similar to this question, I am trying to draw a parametric tube in a PGFplots 3D-plot:

\documentclass{article}

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

\begin{document}
\begin{tikzpicture}
    \begin{axis}
        \addplot3[
            surf,
            samples=2,
            samples y=20,
            y domain=0:360,
            colormap/blackwhite
        ]
        ({sin(y)}, {x}, {cos(y)});
    \end{axis}
\end{tikzpicture}
\end{document}

yielding:

broken 3d tube

I am not sure, how to fix the drawing order of the colormap. It seems quite glitchy as-is.

Putting the domain so that it joins at the bottom, where in the current view there is no overlap of the tube with itself, fixes it (y domain=-70:290):

enter image description here

The issue with that is of course, that once the current view changes, we have to manually adjust the y domain.

How can the colormap overlaying itself be fixed?

3

pgfplots is very smart but sometimes one needs to help it a bit. Here you need z buffer=sort.

\documentclass{article}

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

\begin{document}
\begin{tikzpicture}
    \begin{axis}
        \addplot3[
            surf,
            samples=2,
            samples y=20,
            y domain=0:360,
            colormap/blackwhite,z buffer=sort
        ]
        ({sin(y)}, {x}, {cos(y)});
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

0

I was not planning on answering this question myself, but I found the key z buffer in the PGFplots manual, in Section 4.6.5. Mesh Plots.

Supplying it gives

\documentclass{article}

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

\begin{document}
\begin{tikzpicture}
    \begin{axis}
        \addplot3[
            surf,
            samples=2,
            samples y=20,
            y domain=0:360,
            colormap/blackwhite,
            mesh/interior colormap name=hot,
            z buffer=sort
        ]
        ({sin(y)}, {x}, {cos(y)});
    \end{axis}
\end{tikzpicture}
\end{document}

which works and also allows correct plotting of an interior colormap for the mesh:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.