I am getting an undefined control sequence when using \col in a \foreach loop.
! Undefined control sequence.
\pgfkeyscurrentkey ->\col
\documentclass[tikz, dvipsnames]{standalone}
\usepackage{mathtools}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
samples = 500,
no marks,
xlabel = $\scriptstyle x$,
ylabel = $\scriptstyle y$
]
\foreach \u/\col in {1/red, 2/blue, 3/OliveGreen}{
\addplot+[\col, domain = -4:4, variable = \v]
({(exp(\u) + exp(-\u)) / 2 * cos(deg(v))},
{(exp(\u) - exp(-\u)) / 2 * sin(deg(v))});
}
\end{axis}
\end{tikzpicture}
\end{document}
And also, how can I use \addlegendentry for the plot with a loop?
\expandafter\addplot\expandafter+\expandafter[\col, dom….pgfplotsdoesn’t process the content linear but firstly collects everything and then evaluates it. At this point\colisn’t defined anymore. – Qrrbrbirlbel Sep 05 '13 at 21:40\addlegenentrywhen using\foreach? This part of the question is located below the code. – dustin Sep 05 '13 at 21:44\addlegendentryexpanded{$u =\u$}instead of\addlegendentry. Same problem, different solution. – Qrrbrbirlbel Sep 05 '13 at 21:46\edef– percusse Sep 06 '13 at 05:22