6

I'm making my first steps in 3D graphics in LaTeX. What I got so far is this image

output

In the backgorund one can sense a small D_g; the blue domain should be denoted with that. The red surface should just be a function that lives on the blue domain, so what I'm looking for, as in the 2D case, is whether it is possible do write on the blue surface.

If this is not the case, is there an easy way to reconstruct such a graphic in the classical TikZ way? What is important here, besides the blue domain, is that the red surface has to be steep near some of the boundaries.

How does one determine the best viewing angle? Is it just trial and error, and experience?

Once again: I only need a qualitative sketch of the situation in the image. Even, the axis are not really important. I'm grateful for any comment.

Edit: An additional question: What is the best way to optimize 3D colored graphics for bw output?


Code

\documentclass{minimal}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view={60}{45}]
  \addplot3[surf, samples=30,domain=0:1, y domain=0:1,opacity=1,
  color=blue]
(x,{y*((1/4)*cos(deg(2*pi*x))+1-x/2)},0);

  \node (A) at (0,1,1) [above] {$D_g$};
    \addplot3[surf, domain=0:1, y domain=0:1,color=red,opacity=0.5]
  (x,{y*((1/4)*cos(deg(2*pi*x))+1-x/2)},{(1+sqrt(y)-sqrt(1-y))});
 \end{axis}
\end{tikzpicture}
\end{document}
1
4

I can't tell from your question if you require automatic placement of these labels. Additionally, my code below corrects two minor issues with the z-coordinate specification of the second \addplot3 command which prevented your MWE from compiling: a missing opening brace and an erroneous > character.

If manual positioning is acceptable, nodes can be placed at an arbitrary location on the axes using the axis cs coordinate system specifier (c.f. Section 4.16 of the pgfplots manual), like so:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view={60}{45}]
  \addplot3[surf, samples=30,domain=0:1, y domain=0:1,opacity=1,color=blue] 
    (x,{y*((1/4)*cos(deg(2*pi*x))+1-x/2)},0);
  \node (A) at (axis cs:0.8,0.8,0) {$D_g$};
  \addplot3[surf, domain=0:1, y domain=0:1,color=red,opacity=0.5]
    (x,{y*((1/4)*cos(deg(2*pi*x))+1-x/2)},{(1+sqrt(y)-sqrt(1-y))});
 \end{axis}
\end{tikzpicture}
\end{document}

The coordinates 0.8,0.8,0 may be modified to place the label in any location you desire.

The best viewing angle is subjective and will change if different functions are plotted, so I'm afraid trial and error is the method to use here.

For black and white output, you can use option colormap/blackwhite with the axis environment. Also change the color=<value> options for each plot to some variant of gray, e.g. gray or gray!30.

2
  • Thanks, I fixed it. The label positioning you provided is excellent and I don't need automatic labeling. Thanks for your hints on the manual. – Quickbeam2k1 Jan 29 '14 at 9:50
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Martin Schröder Jan 29 '14 at 9:59

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.