I have a beamer frame with an axis environment that contains a foreach loop. I would like to use the count index deriving from such loop as a variable within the loop. Specifically, I need such variable to affect the visibility and label of the plot. I cannot manage to adapt accordingly neither this nor this chunk of code. I provide hereby a minimum (non) working example. The related picture is obtained by running the currently commented line and while not running (commenting) the line above.
\documentclass[beamer]{standalone}
\usepackage{pgfplots}
\tikzset{
invisible/.style={opacity=0},
visible on/.style={alt={#1{}{invisible}}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}
},
}
\begin{document}
\begin{frame}
\begin{center}
\begin{tikzpicture}
\begin{axis}[width=7cm]
\foreach \p [count=\n from 0] in {0.15, 1.15, 2.15} {
\def\pline{(1-(\p*(\x-3))};
\addplot [mark=none, draw=gray, domain=0:4,visible on=<\n>] {\pline} node [pos=0.25] {\n};
%\addplot [mark=none, draw=gray, domain=0:4] {\pline} node [pos=0.25, fill=white] {L};
}
\end{axis}
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}

