When I use a 3D plot in class, I like representing first, 2D plots along each axis (as if I was "tranching" the 3D graph), and then explain the dynamic in 3D. The Final 3D plot is then easier to assimilate for students.
How can I "tranch" properly a 3D plot with a set of 2D plots passing conditional argument in styles ?
So far, I get the result I like by (inefficiently) superposing the plot with 2 different styles.
It works well but I am reinventing the wheel since the 3D plot facets already exist, i'd just need to display them along the x
only or along the y
only to have what I'd like. I can display, the 2D version in 3D or the 3D only or both which is convenient.
Where am I stuck?
- I created
\newif
s to choose whether i wanted a 3D plot or the set of 2D plot. It's too laborious to be correct. - As a result, how could I pass the argument equivalent to \newif so that the style takes care of the 2D and/or 3D view (and not plot twice the function with 2 distinct styles). It could also handle the granularity of the
samples
to see more or less 2D curves. - Also, as you can see in the tikzset in comment,
2D/.style
3D/.style
generate multiple errors. - No problem to "tranch" based on
y
but\ifTranchX
to try along thex
is not working
Here is MWE
\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{colormap={whitered}{color(0cm)=(white!20!orange); color(2.5cm)=(orange!75!red)}}
\newif\ifTwoD
\newif\ifThreeD
\newif\ifTranchX
\newif\ifTranchY
\TwoDtrue
\ThreeDtrue
%\TranchXtrue
\TranchYtrue
%\tikzset{
%2D/.style ={samples y=10,mesh,patch type=line,thick},
%3D/.style ={surf,opacity=0.2},
%}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
view={-30}{30},
axis lines=left,
axis on top,
axis line style={black!40},
xlabel style ={sloped},
ylabel style ={sloped},
colormap name=whitered,
ticklabel style={font=\small},
samples=51]
\ifTwoD
\ifTranchX
\addplot3[samples=10,mesh,patch type=line,thick]{exp(-x^2-y^2)};
\fi
\ifTranchY
\addplot3[samples y=10,mesh,patch type=line,thick]{exp(-x^2-y^2)};
\fi
\fi
\ifThreeD \addplot3 [surf,opacity=0.2] {exp(-x^2-y^2)}; \fi
\end{axis}
\end{tikzpicture}
\end{document}
NB: On a cultural note, i tried to mimic the color of "papier millimétré" I used to work on in the 80's (in France, but maybe elsewhere ?). papier millimétré
\pgfplotsset
(and not\tikzset
) in\pgfplotsset{ 2D/.style ={samples y=10,mesh,patch type=line,thick}, 3D/.style ={surf,opacity=0.2}, }
I am not sure I understand the question. The output looks good, and using ifs sounds like a good idea. What precisely do you want an answerer to do?