5

Following the issue Color Management with a Family of Curves I couldn't find a proper way of creating the associated table for a family of curves.

I tried to create new columns with respect to the parameter \y (exponent), but without success using \foreach or \pgfplotsinvokeforeach (see comment lines).

Here is the code:

\documentclass[border=1mm]{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.8}

\pgfplotstableread{
1   1
2   4
3   9
4   16
5   25
}\dataQuad

\begin{document}
    \begin{minipage}[c]{0.75\textwidth}
        \begin{tikzpicture}
            \begin{axis}[%
                legend pos=north west,
                domain=0:5,
                cycle list name=color,
                xlabel=${x}$,
                ylabel=${y}$]
            \addplot [smooth] table[x index=0, y index=1] {\dataQuad};
            \legend{$y=x^2$}
            \foreach \y/\c in {3/green,4/red,5/brown}{%
                \edef\temp{\noexpand\addplot [color=\c,smooth] table[x index=0, y expr=\noexpand\thisrowno{0}^\y] {\noexpand\dataQuad};}
            \temp
            \addlegendentryexpanded{$y=x^\y$}
            }
            \end{axis}
        \end{tikzpicture}
    \end{minipage}
%
    \begin{minipage}[c]{0.75\textwidth}
        \pgfplotstablecreatecol[
            create col/assign/.code={%
                \foreach \y in {3,4,5} {%
%                   \pgfplotsinvokeforeach{3,4,5} {%
                    \pgfmathparse{\thisrow{1}*\y}
%                   \thisrow{1}*#1
                }
            \pgfkeyslet{/pgfplots/table/create col/next content}\pgfmathresult
            }
        ]{exp}\dataQuad
        \pgfplotstabletypeset[columns={[index]0,[index]1,exp}]\dataQuad
    \end{minipage}
\end{document}

What goes wrong here? Additionally, a header for each column with reference to each list entry from '{3,4,5}' would be great.

Thanks again, Paul


OK, the error '! Package PGF Math Error: Sorry, an internal routine of the floating point unit' from above occurs when defining a list with \newcommand{\param}{2,3,4,5}, see following MWE:

\documentclass[border=1mm]{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.8}

\pgfplotstableread{
1
2
3
4
5
}\dataQuad

\newcommand{\param}{2,3,4,5}

\pgfplotsforeachungrouped \y in \param {%
    \pgfplotstablecreatecol[
        create col/expr={\thisrow{0}^\y}
    ]{\y}\dataQuad
}

\begin{document}
    \begin{minipage}[c]{0.75\textwidth}
        \begin{tikzpicture}
            \begin{axis}[%
                legend pos=north west,
                domain=0:5,
                cycle list={green, red, black, purple, orange},
                xlabel=${x}$,
                ylabel=${y}$]
            \pgfplotsinvokeforeach{2,...,5}{
                    \addplot +[smooth] table [x index=0, y=#1] \dataQuad;
            }
            \end{axis}
        \end{tikzpicture}
    \end{minipage}

    \begin{minipage}[c]{0.75\textwidth}
        \pgfplotstabletypeset\dataQuad
    \end{minipage}
\end{document}

Do I have to use another approach for predefine a list?

Thanks, Paul

Paul
  • 325
  • 2
  • 7

1 Answers1

6

If I understand your question correctly, you want to create one column for each exponent, and in that column, the content of the first column in the table should be raised to the power of the current column index.

For that, you can loop over the desired exponents, and run \pgfplotstablecreatecol each time. Note that it's much easier to use create col/expr than create col/assign (the latter is a really powerful general purpose method, but if all you want is a mathematical expression, expr is the way to go).

\documentclass[border=1mm]{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.8}

\pgfplotstableread{
1
2
3
4
5
}\dataQuad

\pgfplotsforeachungrouped \y in {2,...,5}{
    \pgfplotstablecreatecol[
        create col/expr={\thisrow{0}^\y}
    ]{\y}\dataQuad
}

\begin{document}
    \begin{minipage}[c]{0.75\textwidth}
        \begin{tikzpicture}
            \begin{axis}[%
                legend pos=north west,
                domain=0:5,
                cycle list={green, red, black, purple, orange},
                xlabel=${x}$,
                ylabel=${y}$]
            \pgfplotsinvokeforeach{2,...,5}{
                    \addplot +[smooth] table [x index=0, y=#1] \dataQuad;
            }
            \end{axis}
        \end{tikzpicture}
    \end{minipage}

    \begin{minipage}[c]{0.75\textwidth}
        \pgfplotstabletypeset\dataQuad
    \end{minipage}
\end{document}
Jake
  • 232,450
  • Thanks a bunch! For my real problem the compiler claims '! Package PGF Math Error: Sorry, an internal routine of the floating point unit'. Do I have to use a \pgfmathparse and the 'fpu'-library somewhere (I can't reproduce the error with small example above)? P.S. I voted for you (...I am still learning to use this website... ;)) – Paul Aug 02 '13 at 12:36
  • Hm, hard to tell. Does the error occur when you're generating the table, or when you're plotting the data? – Jake Aug 02 '13 at 12:42
  • It occurs when generating the table! Compiler:'...got an ill-formatted floating point number `1Y1.1e-2]1Y9.0e-1]{1Y8.5e-1]}{1Y8. 0e-1]}{1Y7.5e-1]}...' Looks for internal handling floating points. My table entries and the exponents are fp. – Paul Aug 02 '13 at 12:49
  • Hm, you can try putting \pgfkeys{/pgf/fpu=true} immediately before the \pgfplotstablecreatecol (inside the loop), and \pgfkeys{/pgf/fpu=false} immediately before the end of the loop. If that doesn't work, you'll probably have to edit your question to include a small example that demonstrates the problem. – Jake Aug 02 '13 at 12:54
  • I tried that without success. When I have an example I will post it here. Thanks, Paul – Paul Aug 02 '13 at 13:02
  • The solution to that problem (shown below) was answered here Package PGF Math Error.... – Paul Aug 12 '13 at 20:28