The following MWE works nicely when I remove the optional argument [\forcol] from the \addplotcommand or when I change it to red, for example. Though I would like the curves to have different colors as defined in my list {1/black,2/red,3/green,4/blue,5/orange}, so I tried it as the following, but then it throws me the error
"! Undefined control sequence. \end{axis}"
\documentclass{article} \usepackage{xcolor} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis} \foreach \foridx/\forcol in {1/black,2/red,3/green,4/blue,5/orange}{ \addplot[\forcol]{x^\foridx}; } \end{axis} \end{tikzpicture} \end{document} What is my mistake? I would like to have this feature to set up a command for plotting many data files.

\pgfplotsforeachungrouped \foridx/\forcol in {1/black,2/red,3/green,4/blue,5/orange}{ \addplot[\forcol]{x^\foridx}; \edef\temp{\noexpand\addplot[\forcol]{x^\foridx};} \temp }tempenvironment. This should be omitted.