4

What I want to do is to produce a 3d plot of a surface of revolution. So far I have achieved the following code...

\documentclass[border= 5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{colormap={bluered}{rgb255(0cm)=(0,0,180);rgb255(1cm)=(0,255,255);rgb255(2cm)=(100,255,0);rgb255(3cm)=(255,255,0);rgb255(4cm)=(255,0,0); rgb255(5cm)=(128,0,0)}} 
\begin{document}
\begin{tikzpicture} 
\begin{axis} [colormap/bluered]
\addplot3 [surf,samples=100,domain=0:180,y domain=0:2*pi]({x},{sin(x)*cos(deg(y))},{sin(x)*sin(deg(y))}); 
\end{axis} 
\end{tikzpicture}
\end{document}

This ends up in the function on sin(x) along the x axis, and rotated around the x axis again forming a lobe...The image is here:

enter image description here

What I need is... the function (let's say sin(x)), to be along the x axis but rotated around the z axis...(The image should be like the waves on the water when a rock falls in...for the sin(x)).

Also there is a problem with the colours...It seems that those yellows on top shouldn't be there...

5

For plots like this, it's typically a good idea to use z buffer=sort to make sure the elements appear in the right order.

To get a surface made up of a function rotated around the z axis, you can use an expression like:

    ({sin(x)*y},{cos(x)*y},{ <function of y> }); 

where function of y is the function you want to rotate:

\documentclass[border= 5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture} 
\begin{axis} [colormap/greenyellow, axis equal]
\addplot3 [surf,shader=faceted interp, samples=25,domain=0:360,y domain=0:1080, z buffer=sort]
    ({sin(x)*y},{cos(x)*y},{cos(y)*50}); 
\end{axis} 
\end{tikzpicture}
\end{document}
|improve this answer|||||
  • That's exactly what I mean... But when trying to compile it I get the following... "./bbb.tex:8: Dimension too large. <recently read> \pgf@xa l.8 \end{axis} ?" bbb is the name of the file.... – Ariscampis Nov 4 '13 at 8:16
  • @Ariscampis: Does that happen when you try to compile my example, or have you changed something in the code? – Jake Nov 4 '13 at 8:27
  • Nothing changed...I copied your code and I pasted it... – Ariscampis Nov 4 '13 at 8:28
  • @Ariscampis: What version of PGFPlots are you using? And how are you compiling the document (pdflatex? lualatex?) – Jake Nov 4 '13 at 8:31
  • 1
    Update successfull! Works like a charm now!!!! Thanks Jake!!! – Ariscampis Nov 4 '13 at 19:28

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.