我检查过一些类似的主题,但是它们确实不是\foreach
帮我解决我的问题。我在环境中遇到了循环问题axis
。我的问题是什么?我该如何解决?这是我的 MWE。
\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\definecolor{mc1}{rgb}{0.368417,0.506779,0.709798}
\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}[declare function={f(\t,\y)=\t*sqrt{abs{\y}};}]
\begin{axis}[
width=100mm,
height=60mm,
view={120}{75},
axis lines=center,
xtick={-1,0,1},
x tick label style={opacity=0.4},
xmin=-1.25,
xmax=1.25,
domain=-1:1,
xlabel={$t$},
xlabel style={opacity=0.4},
x axis line style={opacity=0.6},
ytick={-1,0,1},
y tick label style={opacity=0.4},
ymin=-1.25,
ymax=1.25,
y domain=-1:1,
ylabel={$y$},
ylabel style={opacity=0.4},
y axis line style={opacity=0.6},
ztick={\empty},
zticklabels={\empty},
z tick label style={opacity=0.4},
zmin=-1.25,
zmax=1.25,
zlabel={$z$},
zlabel style={opacity=0.4},
z axis line style={opacity=0.6},
]
%\addplot3[surf,domain=-1:1,y domain=-1:1,color=mc1,opacity=0.2,samples=21,samples y=21,faceted color=mc1!40]{f(x,y)};
\foreach \t in {-1,0,1} {
\edef\temp{\noexpand\draw[variable=\y,domain=-1:1,samples=10,color=mc1,thick] plot (axis cs:\t,\y,{f(\t,\y)});}
\temp
}
\end{axis}
\end{tikzpicture}
\caption{Graphic of $f$.}\label{fig1}
\end{figure}
\end{document}
答案1
谢谢乌尔里克·菲舍尔。
\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\definecolor{mc1}{rgb}{0.368417,0.506779,0.709798}
\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}[declare function={f(\t,\y)=\t*sqrt{abs{\y}};}]
\begin{axis}[
width=100mm,
height=60mm,
view={120}{75},
axis lines=center,
xtick={-1,0,1},
x tick label style={opacity=0.4},
xmin=-1.25,
xmax=1.25,
domain=-1:1,
xlabel={$t$},
xlabel style={opacity=0.4},
x axis line style={opacity=0.6},
ytick={-1,0,1},
y tick label style={opacity=0.4},
ymin=-1.25,
ymax=1.25,
y domain=-1:1,
ylabel={$y$},
ylabel style={opacity=0.4},
y axis line style={opacity=0.6},
ztick={\empty},
zticklabels={\empty},
z tick label style={opacity=0.4},
zmin=-1.25,
zmax=1.25,
zlabel={$z$},
zlabel style={opacity=0.4},
z axis line style={opacity=0.6},
]
%\addplot3[surf,domain=-1:1,y domain=-1:1,color=mc1,opacity=0.2,samples=21,samples y=21,faceted color=mc1!40]{f(x,y)};
\foreach \t in {-1,0,1} {
\edef\temp{\noexpand\draw[variable=\noexpand\y,domain=-1:1,samples=10,color=mc1,thick] plot (axis cs:\t,\noexpand\y,{f(\t,\noexpand\y)});}
\temp
}
\end{axis}
\end{tikzpicture}
\caption{Graphic of $f$.}\label{fig1}
\end{figure}
\end{document}