1

I have checked some similar topics but they did not help me fix my problem. I am experiencing problems with \foreach loop in an axis environment. What is my problem and how can I fix it? Here is my 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}
bkarpuz
  • 2,437

1 Answers1

1

Thanks to UlrikeFischer.

\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}
bkarpuz
  • 2,437