I'm trying to draw 10 functions of ten different colors (actually starting from red and ending with yellow) inside a tikzpicture environment. Problem is that the code reads only the first color (red) and then plot all 10 functions in green Here's the code:
\documentclass{amsart}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage[a4paper, margin=2.5cm]{geometry}
\usepackage{pgfplots}
\usepackage{xcolor}
\pgfplotsset{compat=1.18}
\usepackage{mdframed}
\usepackage{subcaption}
\begin{document}
\begin{figure}[htb]
\begin{mdframed} % un solo riquadro esterno per coerenza visiva
\centering
% --- PRIMA SUBFIGURE ---
\begin{subfigure}[t]{0.45\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[
axis lines=none,
grid=none,
width=\linewidth,
height=0.8\linewidth, % stessa altezza per entrambi
xmin=-1, xmax=4,
ymin=-2, ymax=3,
samples=200,
domain=0:3.1416
]
\addplot[thick,smooth]{2*sin(deg(x))};
\addplot[only marks, mark=*] coordinates {(0,0)};
\addplot[only marks, mark=*] coordinates {(3.1416,0)};
\node[below left] at (axis cs:0,0) {$x_0$};
\node[below right] at (axis cs:3.1416,0) {$x_1$};
\node[below] at (axis cs:1.5,1.9) {$\gamma(t)$};
\end{axis}
\end{tikzpicture}
\end{subfigure}%
\hfill
% --- SECONDA SUBFIGURE ---
\begin{subfigure}[t]{0.45\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[
axis lines=none,
grid=none,
width=\linewidth,
height=0.8\linewidth,
xmin=-1.5, xmax=1.5,
ymin=-1.5, ymax=1.5,
samples=200,
domain=0:360
]
\addplot[thick, parametric] ({-0.5+0.5*cos(x)}, {0.5*sin(x)});
\addplot[only marks, mark=*] coordinates {(0,0)};
\node[right] at (axis cs:0,0) {$x_0$};
\node[left] at (axis cs:-1,0) {$\mu(t)$};
\end{axis}
\end{tikzpicture}
\end{subfigure}
\hfill
\begin{subfigure}[t]{0.45\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[
axis lines=none,
grid=none,
width=\linewidth,
height=0.8\linewidth,
xmin=-1, xmax=4,
ymin=-3, ymax=3,
samples=200,
domain=0:3.1416
]
\addplot[thick,smooth]{2*sin(deg(x))};
\addplot[thick,smooth]{-sin(deg(x))};
\addplot[only marks, mark=*] coordinates {(0,0)};
\addplot[only marks, mark=*] coordinates {(3.1416,0)};
\foreach \n in {1,...,9} {
\pgfmathsetmacro{\t}{\n/10}
\pgfmathsetmacro{\coef}{2 - 3*\t}
\pgfmathtruncatemacro{\perc}{100*\t}
\addplot[
smooth, thick,
red!\perc!black, % gradiente dal verde al blu
domain=0:3.1416,
samples=200
] {\coef*sin(deg(x))};
}
\node[below left] at (axis cs:0,0) {$x_0$};
\node[below right] at (axis cs:3.1416,0) {$x_1$};
\node[above] at (axis cs:1.5,1.9) {$\gamma_0(t)$};
\node[below right] at (axis cs:2.5,-0.4) {$\gamma_1(t)$};
\end{axis}
\end{tikzpicture}
\end{subfigure}
\hfill
\begin{subfigure}[t]{0.45\textwidth} %is here in this subfigure the problem
\centering
\begin{tikzpicture}
\begin{axis}[
axis lines=none,
grid=none,
width=\linewidth,
height=0.8\linewidth,
xmin=-1.5, xmax=1.5,
ymin=-1.5, ymax=1.5,
samples=200,
domain=0:360
]
\foreach \n in {1,...,9} {
\pgfmathsetmacro{\t}{\n/10}
\pgfmathsetmacro{\coefa}{-0.5 + 0.25*\t}
\pgfmathsetmacro{\coefb}{-\coefa}
\pgfmathtruncatemacro{\perc}{100*\t}
\addplot[thick, parametric]({\coefa +\coefb*cos(x)},{\coefb*sin(x)});
};
\addplot[thick, parametric] ({-0.5+0.5*cos(x)}, {0.5*sin(x)});
\addplot[only marks, mark=*] coordinates {(0,0)};
\node[right] at (axis cs:0,0) {$x_0$};
\node[left] at (axis cs:-1,0) {$\mu_0(t)$};
\node[right] at (axis cs:-0.55,0) {$\mu_1(t)$};
\end{axis}
\end{tikzpicture}
\end{subfigure}
\hfill
\end{mdframed}
\caption{Main Caption}
\end{figure}
\end{document}



\percis showing up as undefined.pgfplotsmethod for loops.