I have this minimal file:
\documentclass[]{scrartcl}
\usepackage{filecontents}
\usepackage{pgfplots}
\pgfplotstableset{
header=true,
trim cells=true,
col sep=comma,
}
\begin{document}
\begin{filecontents}{a.dat}
x,y
1,2
2,4
3,6
\end{filecontents}
\begin{filecontents}{b.dat}
x,y
1,3
2,6
3,9
\end{filecontents}
\pgfplotstableread{a.dat}{\DataA}
\pgfplotstableread{b.dat}{\DataB}
\begin{tikzpicture}
\begin{axis}
\addplot table[x=x,y=y]\DataA;\label{plt:dataA}
\addplot table[x=x,y=y]\DataB;\label{plt:dataB}
\end{axis}
\end{tikzpicture}
\end{document}
the actual file has many more input files, but for each I have one line with \addplot
. Now I thought, instead of having many lines of \addplot
I could use \pgfplotsinvokeforeach
to call it.
something like this:
...
\pgfplotsinvokeforeach{A,B}{
\addplot table[x=x,y=y]\Data#1;\label{plt:data#1}
}
...
the label part works as expected, and the \Data#1
part does not (also as expected). I tried some combinations of \csname
and \endcsname
but had no success.
how can I use this loop structure to add multiple plots from multiple tables?
\pgfplotsinvokeforeach{a,b}{\addplot table[x=x,y=y]{#1.dat};\label{plt:data:#1}}
?