1

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?

3
  • Maybe you can use the files directly: \pgfplotsinvokeforeach{a,b}{\addplot table[x=x,y=y]{#1.dat};\label{plt:data:#1}}?
    – esdd
    Commented Nov 17, 2015 at 10:05
  • @Garonenur, did the trick of esdd help you or do you need further assistance? In the first case I would vote to close this question as being solved. Commented Nov 2, 2016 at 23:02
  • @StefanPinnow sorry, I missed this comment - I will check it and close this ASAP, maybe add his comment as an answer to accept.
    – Garonenur
    Commented Nov 7, 2016 at 11:25

1 Answer 1

2

thanks to @esdd,

his answer in the comments to this question works for this mwe. One can simply use

\pgfplotsinvokeforeach{a,b}{\addplot table[x=x,y=y]{#1.dat};\label{plt:data:#1}}

The filename directly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .