7

What I want is to plot my function from y=0-->y=3 and then from y=3,2-->y=6. I want to ommit the space between 3 and 3,2. This is my code:

\documentclass[border= 5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis} [ restrict z to domain=0:85,zmax=85,zmin=0, width=30 cm, height=20 cm]
\addplot3 [surf, samples=50,domain=-155:205,y domain=0:6, z buffer=sort]({sin(x)*y},{cos(x)*y},{17.22 + 5.53*y + 1.161*tan((180/pi)*(29.97 + y))}); 
\end{axis} 
\end{tikzpicture}
\end{document}

I tried to use the \addplot twice, but then the second plot appears on top of the first (and not inside or around as it should)... Any ideas how I could split the y domain?

7

You can make use of the coordinate filters.

The following code makes use of some utility functions of pgfplots which simplify programmatic comparisons:

\documentclass[border= 5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis} [ restrict z to domain=0:85,zmax=85,zmin=0,
    filter discard warning=false,
    y filter/.code={%
        \let\input=\pgfmathresult
        \pgfmathparse{v}%
        \let\checkValue=\pgfmathresult
        \pgfmathfloatparsenumber{3}%
        \let\lower=\pgfmathresult
        \pgfmathfloatparsenumber{3.2}%
        \let\upper=\pgfmathresult
        \pgfplotscoordmath{float}{if less than}{\checkValue}{\lower}{%
            \let\pgfmathresult=\input
        }{%
            \pgfplotscoordmath{float}{if less than}{\checkValue}{\upper}{%
                \let\pgfmathresult=\empty
            }{%
                \let\pgfmathresult=\input
            }%
        }%
    },
    width=30 cm, height=20 cm]
\addplot3 [surf, samples=50,domain=-155:205,
    variable y=\v,
    y domain=0:6, z buffer=sort]
    ({sin(x)*v},{cos(x)*v},{17.22 + 5.53*v + 1.161*tan((180/pi)*(29.97 + v))}); 
\end{axis} 
\end{tikzpicture}
\end{document}

enter image description here

The idea is to return \input if the filter is a "no-op" and to return \empty if the filter decides that it should get rid of stuff. In order to evaluate the parameter, I introduced a new name variable y=\v such that it is not overwritten with the final y coordinate.

Here is the result without the filter: enter image description here

  • Very helpful my friend! Thanks! I managed it though by adding \addplot3 from the back to the front (3 times)... First the external half back turn, then the inside full turn and finally the external front half turn... – Ariscampis Nov 26 '13 at 19:36
  • That is also a good solution. Would you mind posting it here? Others may want to learn from it. – Christian Feuersänger Nov 30 '13 at 9:19
2

Well after some consideration, since every \addplot3 I added kept appearing on top of the previous, I decided to "build" the graph from the back side to the front... Firstly I created this:

\documentclass[border= 5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis} [ restrict z to domain=0:85,zmax=85,zmin=0, width=30 cm, height=20 cm, ymin=-6 ]
\addplot3 [surf, samples=30,domain=-100:80,y domain=3.2:6, z buffer=sort]({sin(x)*y},{cos(x)*y},{17.22 + 5.53*y + 1.161*tan((180/pi)*(29.97 + y))}); 
\end{axis} 
\end{tikzpicture}
\end{document}

which results to the half back turn when x is from 3.2 to 6 as shown enter image description here

after I added the inner full turn with x to be from 0 to 3 ,by adding this:

\addplot3 [surf, samples=30,domain=-100:260,y domain=0:3, z buffer=sort]({sin(x)*y},{cos(x)*y},{17.22 + 5.53*y + 1.161*tan((180/pi)*(29.97 + y))});

The full code is:

\documentclass[border= 5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis} [ restrict z to domain=0:85,zmax=85,zmin=0, width=30 cm, height=20 cm, ymin=-6 ]
\addplot3 [surf, samples=30,domain=-100:80,y domain=3.2:6, z buffer=sort]({sin(x)*y},{cos(x)*y},{17.22 + 5.53*y + 1.161*tan((180/pi)*(29.97 + y))}); 
\addplot3 [surf, samples=30,domain=-100:260,y domain=0:3, z buffer=sort]({sin(x)*y},{cos(x)*y},{17.22 + 5.53*y + 1.161*tan((180/pi)*(29.97 + y))});
\end{axis} 
\end{tikzpicture}
\end{document}

This results as:

enter image description here

As you can see between 3 and 3.2 the graph is blank! While in the first presented solution this gap is painted!

And finally I added the front half turn with x from 3.2 to 6 by adding this line

\addplot3 [surf, samples=30,domain=80:260,y domain=3.2:6, z buffer=sort]({sin(x)*y},{cos(x)*y},{17.22 + 5.53*y + 1.161*tan((180/pi)*(29.97 + y))}); 

The full code is :

\documentclass[border= 5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis} [ restrict z to domain=0:85,zmax=85,zmin=0, width=30 cm, height=20 cm, ymin=-6 ]
\addplot3 [surf, samples=30,domain=-100:80,y domain=3.2:6, z buffer=sort]({sin(x)*y},{cos(x)*y},{17.22 + 5.53*y + 1.161*tan((180/pi)*(29.97 + y))}); 
\addplot3 [surf, samples=30,domain=-100:260,y domain=0:3, z buffer=sort]({sin(x)*y},{cos(x)*y},{17.22 + 5.53*y + 1.161*tan((180/pi)*(29.97 + y))});
\addplot3 [surf, samples=30,domain=80:260,y domain=3.2:6, z buffer=sort]({sin(x)*y},{cos(x)*y},{17.22 + 5.53*y + 1.161*tan((180/pi)*(29.97 + y))}); 
\end{axis} 
\end{tikzpicture}
\end{document}

and the result !!!

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.