In the example below I am trying to set explicitly some numbered styles and then loop through those styles in a plot. However the variable \i doesn't seem to expand correctly in mystyle\i (however it does in \i*x**2). How can I make this work?
Note that I don't want to specify a cycle list in this case.
\documentclass[tikz]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}
\pgfplotsset{
compat=1.13,
mystyle1/.style={red,dashed},
mystyle2/.style={black,dotted},
mystyle3/.style={blue},
samples=100
}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\foreach \i in {1,2,3}{
% \addplot[no markers,mystyle2] gnuplot {\i*x**2};%works
\addplot[no markers,mystyle\i] gnuplot {\i*x**2};
}
\end{axis}
\end{tikzpicture}
\end{document}
\pgfplotsinvokeforeach{1,2,3}{..... }then instead of\iyou can use#1. That would be inserted in expanded state – percusse Jun 25 '16 at 11:31\foreach \i in {...}{ \foreach \j in {...}{}}– student Jun 25 '16 at 15:49