I wanted to make a macro \simplePlotWithFuncs creating plots both from .csv files and from given functions. I need it to be quite versatile, so I can set a lot of things. Because of limited number of parameters in the LaTeX macros I'm forced to use some of them for multiple arguments and parse those afterwards.

The problem is, this approach worked OK until I needed to give parameters to the addplot macro in axis environment. There I'm getting different errors and I don't know, how to solve this.

I have seen similar questions:

\foreach not behaving in axis environment

Using foreach loop variable as node label in pgfplots

Adding to a \foreach variable in pgfplots

Problems using \addlegendentry in a loop with pgfplots

But, unfortunately, I'm still not able to solve the problem.

My attempts

  1. I've tried to use \evaluate parameter in pgfplots \foreach cycle:

    \foreach [evaluate=\datacol(1) as \datacolI] \datafile in {#1} {
    \addplot+[only marks, mark=square*] table [x=\datacolI, y=time, col sep=comma] {\datafile};
  2. I've also tried to use the construction \edef\variable{\noexpand}, but it doesn't work, too:

    \foreach \datafile in {#1} {
     \edef\temp{\noexpand\addplot+[only marks, mark=square*] table [x=\datacolI, y=time, col sep=comma] {\datafile}};


! Incomplete \iffalse; all text was ignored after line 70.
<inserted text> 
<*> main.tex

! Emergency stop.
<inserted text> 
<*> main.tex

!  ==> Fatal error occurred, no output PDF file produced!

Code with my attempt

\usepackage{subfig}     % makra pro "podobrazky" a "podtabulky"
\usepackage{tikz}       % makra pro kresleni



\begin{tikzpicture}[domain=0:25, scale=0.75, transform shape]
legend pos=#4,
grid style=dashed,
cycle list name = color list,
each nth point = 1,
filter discard warning=false
\foreach [evaluate=\datacol(1) as \datacolI] \datafile in {#1} {
    \addplot+[only marks, mark=square*] table [x=\datacolI, y=time, col sep=comma] {\datafile};
\pgfplotsset{cycle list shift=\value{counter}-1}
\foreach \func in {#9} {
    \addplot+[mark=none, dashed]{\func};
{\small #8}


    {Number of processes & Time [s]}
    {north east}
    {size 10x10x10}
    {Stiffness matrix assembling speed dependence on decomposition style}   
    {Fixed size of problem. Changing style of the decomposition - ratio of MPI processes and threads. Number of threads per process is computed by the formula $\frac{24}{nprocs}$. Points are measured values, dashed line is a hyperbola got by inverse regression.}
    {0.066181 + 0.548915/x}

CSV file


I managed to make it work using the \check command from arrarjobx package:

  • retrieve datacol(1) with the \checkdatacol command:
  • then use \datacolI in your loop:
\foreach \datafile in {#1} {
    \addplot+[only marks, mark=square*] table [x=\datacolI, y=time, col sep=comma] {\datafile};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.