Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Why does \pgfplotsinvokeforeach produce

ERROR: Undefined control sequence.

when there are plotting macros before it inside a groupplot?

\documentclass{article}

\usepackage{pgfplots}

\usepgfplotslibrary{groupplots}

\begin{document}

\begin{figure}
  \begin{tikzpicture}
    \begin{groupplot}[group style={group size=3 by 1}]
      \nextgroupplot        % When this and...
      \addplot{x^1};        % this line is commented there is no error
      \pgfplotsinvokeforeach{2,3}{%
        \nextgroupplot
        \addplot{x^#1};%
      }
   \end{groupplot}
 \end{tikzpicture} 
\end{figure}

\end{document}
share|improve this question
    
The arguments are expanded so \nextgroupplot needs a \noexpand just before that. –  percusse Aug 6 '12 at 15:03
    
@percusse But then the output is several plots in one axis and not several plots in their own axis. Maybe I am using the wrong approach. What I want to do is to be able to do is to have different options for the first \nextgroupplot than the rest (in the loop). –  N.N. Aug 6 '12 at 15:08
add comment

1 Answer

up vote 1 down vote accepted

I'm not 100% sure but this is due to the grouping inside the foreach loop such that pgfplots thinks there is a nesting going on which is not allowed. So a little bit manual ungrouped work, gives a result.

\documentclass{article}

\usepackage{pgfplots}

\usepgfplotslibrary{groupplots}

\begin{document}

\begin{figure}
  \begin{tikzpicture}[scale=0.7]
    \begin{groupplot}[group style={group size=3 by 1}]
      \pgfplotsforeachungrouped \x in {1,2,3}{%
        \edef\temp{\noexpand\nextgroupplot%
        \noexpand\addplot{x^\x};%
      }\temp
    }
   \end{groupplot}
 \end{tikzpicture} 
\end{figure}

\end{document}

enter image description here

share|improve this answer
    
You can take out the first plot. I forgot that, sorry. –  percusse Aug 6 '12 at 23:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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