1

I am trying to reuse the example shown in this page for another polar plot. that is r=a*sin(n.theta). The output is kind of what I expect as I will post here

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{pgfplots} 
\pgfplotsset{width=8cm,compat=1.16}
\usepgfplotslibrary{polar} 
\usepackage{subcaption}
\usepackage{floatrow} 
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines = none,
xmin=-1, xmax=1,
ymin=-1, ymax=1,
zmin=0, zmax=1,
] %<- done it in a similar way to 2D plots not quite sure it worsk liek that in 3D
\addplot3[domain=54:126,domain y=0:180,samples=31,
colormap/blackwhite,surf,%mesh,point meta=1, %<-if you want a mesh
z buffer=sort]
({(sin(5*x)*cos(x))*cos(y)}, 
{(sin(5*x)*cos(x))*sin(y)}, 
{(sin(5*x))*sin(x)});
\end{axis}
\end{tikzpicture}
\end{document}

but the negative part circled in red in the attached picture I am not able to get rid of it. Many thanks in advance,enter image description here

Mazen
  • 139
  • 8
  • 2
    Well, {(sin(5*x))*sin(x)} does become negative in the domain=54:126, so what do you expect? Or, in other words, what do you want to achieve? –  Oct 10 '19 at 19:10
  • Yes I agree and would expect to have a negative part but why it appear while I use zmin=0? this is not yet clear to me. – Mazen Oct 11 '19 at 12:58

1 Answers1

0

If your question is how to remove the part with negative z: this is one way.

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{pgfplots} 
\pgfplotsset{width=8cm,compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines = none,
xmin=-1, xmax=1,
ymin=-1, ymax=1,
zmin=0, zmax=1,
] %<- done it in a similar way to 2D plots not quite sure it worsk liek that in 3D
\addplot3[domain=54:126,domain y=0:180,samples=31,
colormap/blackwhite,surf,%mesh,point meta=1, %<-if you want a mesh
z buffer=sort]
({ifthenelse((sin(5*x))*sin(x)>0,(sin(5*x)*cos(x))*cos(y),0)}, 
{ifthenelse((sin(5*x))*sin(x)>0,(sin(5*x)*cos(x))*sin(y),0)}, 
{max((sin(5*x))*sin(x),0)});
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Other ways include using filters, or just using other domains.

  • That is a much better as we render a clean version of what we want. However, why it cannot exclude the part below using the zmin, zmax macros? Is it a programming problem or a rendering problem? Many thanks, – Mazen Oct 11 '19 at 12:56
  • @Mazen It is a 3D “problem “. You cannot simply trim the graph by clipping it. Points with a smaller z coordinate may be higher up in the projected graph if they have other X and y values. –  Oct 11 '19 at 14:59