LaTeX forum ⇒ Graphics, Figures & TablesShaded ellipsoid with PGFplots

Information and discussion about graphics, figures & tables in LaTeX documents.
Tyrion1989
Posts: 2
Joined: Thu Aug 13, 2015 1:05 pm

Shaded ellipsoid with PGFplots

Postby Tyrion1989 » Thu Aug 13, 2015 1:42 pm

Hey, I'm trying to display a shaded 3D ellipsoid with axis labels with PGFplots. So far I achieved this.
  1. \documentclass{standalone}
  2. \usepackage{tikz}
  3. \usepackage{pgfplots,tikz-3dplot}
  4. \begin{document}
  5. \begin{tikzpicture}
  6. \begin{axis}[%
  7. width=0.8\textwidth,
  8. axis equal,
  9. axis lines = center,
  10. y label style={at={(axis cs:0,2,0)},anchor=west},
  11. xlabel = {$\lambda_1,\ \vec{e}_1$},
  12. ylabel = {$\lambda_2,\ \vec{e}_2$},
  13. zlabel = {$\lambda_3,\ \vec{e}_3$},
  14. ticks=none,
  15. ]
  16. \addplot3[%
  17. shader=interp,
  18. opacity = 0.3,
  19. fill opacity=0.3,
  20. surf,
  21. colormap/blackwhite,
  22. variable = \u,
  23. variable y = \v,
  24. domain = 0:180,
  25. y domain = 0:360,
  26. ]
  27. ({2*cos(u)*sin(v)}, {2*sin(u)*sin(v)}, {0.5*cos(v)});
  28. \end{axis}
  29. \end{tikzpicture}
  30. \end{document}

The z label is at the right position in my PDF document, I dont't know why it is deplaced here.
This shading does not give a 3D impression, I would like to have somethin like in the attached file. Is it possible to define a new 3d shading in this coordinate system? I could not find such a command in the pgfplot documentation. All predefined shadings are not suitable.
Glad for any help!
Attachments
FA_tensor.png
FA_tensor.png (52.96 KiB) Viewed 1981 times

Tags:

User avatar
Stefan Kottwitz
Site Admin
Posts: 8534
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Thu Aug 13, 2015 3:03 pm

Welcome to the forum!

You could use point meta = u. And you could play with the colormap, as I did on the axis.

I added colormap={}{ gray(0cm)=(0.8); gray(1cm)=(0);} and point meta = u to the plot:

ellipsoid.png
ellipsoid.png (20.53 KiB) Viewed 1964 times


edit: above was rendered from PDF to PNG by GIMP, seems to become too dark, here's how my previewer and Overleaf render it:

ellipsoid-lighter.png
ellipsoid-lighter.png (28.65 KiB) Viewed 1959 times


Full code:

  1. \documentclass{standalone}
  2. \usepackage{tikz}
  3. \usepackage{pgfplots,tikz-3dplot}
  4. \makeatother
  5. \begin{document}
  6. \begin{tikzpicture}
  7. \begin{axis}[%
  8. width=0.8\textwidth,
  9. axis equal,
  10. axis lines = center,
  11. y label style={at={(axis cs:0,2,0)},anchor=west},
  12. xlabel = {$\lambda_1,\ \vec{e}_1$},
  13. ylabel = {$\lambda_2,\ \vec{e}_2$},
  14. zlabel = {$\lambda_3,\ \vec{e}_3$},
  15. ticks=none,
  16. colormap={}{ gray(0cm)=(0.8); gray(1cm)=(0);}
  17. ]
  18. \addplot3[%
  19. shader=interp,
  20. opacity = 0.3,
  21. fill opacity=0.3,
  22. surf,
  23. variable = \u,
  24. variable y = \v,
  25. domain = 0:180,
  26. y domain = 0:360,
  27. point meta=u,
  28. samples = 50,
  29. ]
  30. ({2*cos(u)*sin(v)}, {2*sin(u)*sin(v)}, {0.5*cos(v)});
  31. \end{axis}
  32. \end{tikzpicture}
  33. \end{document}


Stefan
Site admin

Tyrion1989
Posts: 2
Joined: Thu Aug 13, 2015 1:05 pm

Postby Tyrion1989 » Thu Aug 13, 2015 5:15 pm

Hi, the problem is that the shading coordinate system is still wrong. I want the shading to look like if a light bulb would shine on the ellipsoid. So the colormap should extend from the top maybe and extend in all direction isotropically. Right now there is this "line" dividing the ellipsoid into two halfs. The grey parts on the left side of the upper half should be right so the shading has to be flipped at the y axis for the upper half.

I will try to seperate the ellipsoid into two plots, just have to change the variable domains.

Thanks!


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 7 guests