tikz.dev / PGFplots Manual

Manual for Package pgfplots
2D/3D Plots in LA, Version 1.18.1
http://sourceforge.net/projects/pgfplots

PGFplotsTable

\(\newcommand{\footnotename}{footnote}\) \(\def \LWRfootnote {1}\) \(\newcommand {\footnote }[2][\LWRfootnote ]{{}^{\mathrm {#1}}}\) \(\newcommand {\footnotemark }[1][\LWRfootnote ]{{}^{\mathrm {#1}}}\) \(\let \LWRorighspace \hspace \) \(\renewcommand {\hspace }{\ifstar \LWRorighspace \LWRorighspace }\) \(\newcommand {\mathnormal }[1]{{#1}}\) \(\newcommand \ensuremath [1]{#1}\) \(\newcommand {\LWRframebox }[2][]{\fbox {#2}} \newcommand {\framebox }[1][]{\LWRframebox } \) \(\newcommand {\setlength }[2]{}\) \(\newcommand {\addtolength }[2]{}\) \(\newcommand {\setcounter }[2]{}\) \(\newcommand {\addtocounter }[2]{}\) \(\newcommand {\arabic }[1]{}\) \(\newcommand {\number }[1]{}\) \(\newcommand {\noalign }[1]{\text {#1}\notag \\}\) \(\newcommand {\cline }[1]{}\) \(\newcommand {\directlua }[1]{\text {(directlua)}}\) \(\newcommand {\luatexdirectlua }[1]{\text {(directlua)}}\) \(\newcommand {\protect }{}\) \(\def \LWRabsorbnumber #1 {}\) \(\def \LWRabsorbquotenumber "#1 {}\) \(\newcommand {\LWRabsorboption }[1][]{}\) \(\newcommand {\LWRabsorbtwooptions }[1][]{\LWRabsorboption }\) \(\def \mathchar {\ifnextchar "\LWRabsorbquotenumber \LWRabsorbnumber }\) \(\def \mathcode #1={\mathchar }\) \(\let \delcode \mathcode \) \(\let \delimiter \mathchar \) \(\def \oe {\unicode {x0153}}\) \(\def \OE {\unicode {x0152}}\) \(\def \ae {\unicode {x00E6}}\) \(\def \AE {\unicode {x00C6}}\) \(\def \aa {\unicode {x00E5}}\) \(\def \AA {\unicode {x00C5}}\) \(\def \o {\unicode {x00F8}}\) \(\def \O {\unicode {x00D8}}\) \(\def \l {\unicode {x0142}}\) \(\def \L {\unicode {x0141}}\) \(\def \ss {\unicode {x00DF}}\) \(\def \SS {\unicode {x1E9E}}\) \(\def \dag {\unicode {x2020}}\) \(\def \ddag {\unicode {x2021}}\) \(\def \P {\unicode {x00B6}}\) \(\def \copyright {\unicode {x00A9}}\) \(\def \pounds {\unicode {x00A3}}\) \(\let \LWRref \ref \) \(\renewcommand {\ref }{\ifstar \LWRref \LWRref }\) \( \newcommand {\multicolumn }[3]{#3}\) \(\require {textcomp}\) \( \newcommand {\meta }[1]{\langle \textit {#1}\rangle } \) \(\newcommand {\toprule }[1][]{\hline }\) \(\let \midrule \toprule \) \(\let \bottomrule \toprule \) \(\def \LWRbooktabscmidruleparen (#1)#2{}\) \(\newcommand {\LWRbooktabscmidrulenoparen }[1]{}\) \(\newcommand {\cmidrule }[1][]{\ifnextchar (\LWRbooktabscmidruleparen \LWRbooktabscmidrulenoparen }\) \(\newcommand {\morecmidrules }{}\) \(\newcommand {\specialrule }[3]{\hline }\) \(\newcommand {\addlinespace }[1][]{}\) \(\require {colortbl}\) \(\let \LWRorigcolumncolor \columncolor \) \(\renewcommand {\columncolor }[2][named]{\LWRorigcolumncolor [#1]{#2}\LWRabsorbtwooptions }\) \(\let \LWRorigrowcolor \rowcolor \) \(\renewcommand {\rowcolor }[2][named]{\LWRorigrowcolor [#1]{#2}\LWRabsorbtwooptions }\) \(\let \LWRorigcellcolor \cellcolor \) \(\renewcommand {\cellcolor }[2][named]{\LWRorigcellcolor [#1]{#2}\LWRabsorbtwooptions }\) \(\newcommand {\intertext }[1]{\text {#1}\notag \\}\) \(\let \Hat \hat \) \(\let \Check \check \) \(\let \Tilde \tilde \) \(\let \Acute \acute \) \(\let \Grave \grave \) \(\let \Dot \dot \) \(\let \Ddot \ddot \) \(\let \Breve \breve \) \(\let \Bar \bar \) \(\let \Vec \vec \) \(\newcommand {\nicefrac }[3][]{\mathinner {{}^{#2}\!/\!_{#3}}}\)

6.3Generating Data in New Tables or Columns

It is possible to create new tables from scratch or to change tables after they have been loaded from disk.

6.3.1Creating New Tables From Scratch
  • \pgfplotstablenew[(math image)options(math image)]{(math image)row count(math image)}{(math image)\table(math image)}

  • \pgfplotstablenew*[(math image)options(math image)]{(math image)row count(math image)}{(math image)\table(math image)}

  • Creates a new table from scratch.

    The new table will contain all columns listed in the columns key. For \pgfplotstablenew, the columns key needs to be provided in [(math image)options(math image)]. For \pgfplotstablenew*, the current value of columns is used, no matter where and when it has been set.

    Furthermore, there must be create on use statements (see the next subsection) for every column which shall be generated.106 Columns are generated independently, in the order of appearance in columns. As soon as a column is complete, it can be accessed using any of the basic level access mechanisms. Thus, you can build columns which depend on each other.

    The table will contain exactly (math image)row count(math image) rows. If (math image)row count(math image) is an \pgfplotstablegetrowsof statement, that statement will be executed and the resulting number of rows be used. Otherwise, (math image)row count(math image) will be evaluated as number.

    (image)

    % this key setting could be provided in the document's preamble: \pgfplotstableset{ % define how the 'new' column shall be filled: create on use/new/.style={create col/set list={4,5,6,7,...,10}}} % create a new table with 11 rows and column 'new': \pgfplotstablenew[columns={new}]{11}\loadedtable % show it: \pgfplotstabletypeset[empty cells with={---}]\loadedtable

    (image)

    % create a new table with 11 rows and column 'new': \pgfplotstablenew[ % define how the 'new' column shall be filled: create on use/new/.style={create col/expr={factorial(15+\pgfplotstablerow)}}, columns={new}] {11} \loadedtable % show it: \pgfplotstabletypeset\loadedtable
  • \pgfplotstablevertcat{(math image)\table1(math image)}{(math image)\table2 or filename(math image)}

  • Appends the contents of (math image)\table2(math image) to (math image)\table1(math image) (“vertical concatenation”). To be more precise, only columns which exist already in (math image)\table1(math image) will be appended and every column which exists in (math image)\table1(math image) must exist in (math image)\table2(math image) (or there must be alias or create on use specifications to generate them).

    If the second argument is a file name, that file will be loaded from disk.

    If (math image)\table1(math image) does not exist, (math image)\table2(math image) will be copied to (math image)\table1(math image).

    \pgfplotstablevertcat{\output}{datafile1} % loads `datafile1' -> `\output' \pgfplotstablevertcat{\output}{datafile2} % appends rows of datafile2 \pgfplotstablevertcat{\output}{datafile3} % appends rows of datafile3

Remark:

The output table (math image)\table1(math image) will be defined in the current scope and it will be erased afterwards. The current scope is delimited by an extra set of curly braces. However, every environment and, unfortunately, the TikZ \foreach statement as well, introduce scopes.

pgfplots has some some loop statements which do not introduce extra scopes. For example,

\pgfplotsforeachungrouped \i in {1,2,...,10} {% \pgfplotstablevertcat{\output}{datafile\i} % appends `datafile\i' -> `\output' }%

These looping macros are explained in the manual of pgfplots, reference section “Miscellaneous Commands”

  • \pgfplotstableclear{(math image)\table(math image)}

  • Clears a table. Note that it is much more reliable to introduce extra curly braces ‘{ ... }’ around table operations – these braces define the scope of a variable (including tables).

106 Currently, you need to provide at least one column: the implementation gets confused for completely empty tables. If you do not provide any column name, a dummy column will be created.

6.3.2Creating New Columns From Existing Ones
  • \pgfplotstablecreatecol[(math image)options(math image)]{(math image)new col name(math image)}{(math image)\table(math image)}

  • Creates a new column named (math image)new col name(math image) and appends it to an already existing table (math image)\table(math image).

    End users probably don’t need to use \pgfplotstablecreatecol directly at all – there is the high-level framework create on use which invokes it internally and can be used with simple key–value assignments (see below). However, this documentation explains how to use values of existing columns to fill new cells.

    This command offers a flexible framework to generate new columns. It has been designed to create new columns using the already existing values – for example using logical or numerical methods to combine existing values. It provides fast access to a row’s value, the previous row’s value and the next row’s value.

    The following documentation is for everyone who wants to write specialized columns. It is not particularly difficult; it is just technical and it requires some knowledge of pgfkeys. If you don’t like it, you can resort to predefined column generation styles – and enable those styles in (math image)options(math image).

    The column entries will be created using the command key create col/assign. It will be invoked for every row of the table. It is supposed to assign contents to create col/next content. During the evaluation, the macro \thisrow{(math image)col name(math image)} expands to the current row’s value of the column identified by (math image)col name(math image). Furthermore, \nextrow{(math image)col name(math image)} expands to the next row’s value of the designated column and \prevrow{(math image)col name(math image)} expands to the value of the previous row.

    So, the idea is to simply redefine the command key create col/assign in such a way that it fills new cells as desired.

    Two special assign routines are available for the first and last row: The contents for the last row is computed with create col/assign last. Its semantics is the same. The contents for the first row is computed with create col/assign first to simplify special cases here. These first and last commands are optional, their default is to invoke the normal assign routine.

    The evaluation of the assign keys is done in local groups (i.e. any local definitions will be cleared afterwards).

    The following macros are useful during cell assignments:

    • 1. \prevrow{(math image)col name(math image)} / \getprevrow{(math image)col name(math image)}{(math image)\macro(math image)}

      These two routines return the value stored in the previous row of the designated column (math image)col name(math image). The get routine stores it into (math image)\macro(math image).

      The argument (math image)col name(math image) has to denote either an existing column name or one for which an alias/(math image)col name(math image) exists.

    • 2. \thisrow{(math image)col name(math image)} / \getthisrow{(math image)col name(math image)}{(math image)\macro(math image)}

      These two routines return the current row’s value stored in the designated column. The get routine stores it into (math image)\macro(math image).

      The argument (math image)col name(math image) has to denote either an existing column name or one for which an alias/(math image)col name(math image) exists.

    • 3. \nextrow{(math image)col name(math image)} / \getnextrow{(math image)col name(math image)}{(math image)\macro(math image)}

      These two routines return the next row’s value.

      The argument (math image)col name(math image) has to denote either an existing column name or one for which an alias/(math image)col name(math image) exists.

    • 4. \pgfplotstablerow and \pgfplotstablerows which contain the current row’s index and the total number of rows, respectively. See page (page for section 6.1.2) for details.

    • 5. \pgfmathaccuma and \pgfmathaccumb can be used to transport intermediate results. Both maintain their value from one column assignment to the next. All other local variables will be deleted after leaving the assignment routines. The initial value is the empty string for both of them unless they are already initialized by column creation styles.

    • 6. \pgfplotstablename a macro containing the name of the currently processed table (i.e. it contains the second argument of \pgfplotstablecreatecol).

    • 7. commands which are valid throughout every part of this package, for example \pgfplotstablerow to get the current row index or \pgfplotstablerows to get the total number of rows.

    The (math image)col name(math image) is expected to be a physical column name, no alias or column index is allowed (unless column indices and column names are the same).

    The following example takes our well-known input table and creates a copy of the level column. Furthermore, it produces a lot of output to show the available macros. Finally, it uses \pgfkeyslet to assign the contents of the resulting \entry to next content.

    (image)

    \pgfplotstableread{pgfplotstable.example1.dat}\loadedtable \pgfplotstablecreatecol[ create col/assign/.code={% \getthisrow{level}\entry \getnextrow{level}\nextentry \edef\entry{thisrow=\entry; nextrow=\nextentry. (\#\pgfplotstablerow/\pgfplotstablerows)}% \pgfkeyslet{/pgfplots/table/create col/next content}\entry }] {new}\loadedtable \pgfplotstabletypeset[ column type=l, columns={level,new}, columns/new/.style={string type} ]\loadedtable

    There is one more specialty: you can use columns={(math image)column list(math image)} to reduce the runtime complexity of this command. This works only if the columns key is provided directly into (math image)options(math image). In this case \thisrow and its variants are only defined for those columns listed in the columns value.

Limitations.

Currently, you can only access three values of one column at a time: the current row, the previous row and the next row. Access to arbitrary indices is not (yet) supported.

Remark:

If you’d like to create a table from scratch using this command (or the related create on use simplification), take a look at \pgfplotstablenew.

The default implementation of assign is to produce empty strings. The default implementation of assign last is to invoke assign, so in case you never really use the next row’s value, you won’t need to touch assign last. The same holds for assign first.

  • /pgfplots/table/create on use/(math image)col name(math image)/.style={(math image)create options(math image)}

  • Allows “lazy creation” of the column (math image)col name(math image). Whenever the column (math image)col name(math image) is queried by name, for example in an \pgfplotstabletypeset command, and such a column does not exist already, it is created on the fly.

    (image)

    % requires \usepackage{array} \pgfplotstableset{% could be used in preamble create on use/quot1/.style= {create col/quotient={error1}}} \pgfplotstabletypeset[ columns={error1,quot1}, columns/error1/.style={sci,sci zerofill}, columns/quot1/.style={dec sep align}] {pgfplotstable.example1.dat}

    The example above queries quot1 which does not yet exist in the input file. Therefore, it is checked whether a create on use style for quot1 exists. This is the case, so it is used to create the missing column. The create col/quotient key is discussed below; it computes quotients of successive rows in column error1.

    A create on use specification is translated into

    \pgfplotstablecreatecol[(math image)create options(math image)]{(math image)col name(math image)}{(math image)the table(math image)},

    or, equivalently, into

    \pgfplotstablecreatecol[create on use/(math image)col name(math image)]{(math image)col name(math image)}{(math image)the table(math image)}.

    This feature allows some laziness, because you can omit the lengthy table modifications. However, laziness may cost something: in the example above, the generated column will be lost after returning from \pgfplotstabletypeset.

    The create on use has higher priority than alias.

    In case (math image)col name(math image) contains characters which are required for key settings, you need to use braces around it: “create on use/{name=wi/th,special}/.style={...}”.

    More examples for create on use are shown below while discussing the available column creation styles.

    Note that create on use is also available within pgfplots, in \addplot table when used together with the read completely key.

6.3.3Predefined Column Generation Methods

The following keys can be used in both \pgfplotstablecreatecol and the easier create on use frameworks.

6.3.3.1Acquiring Data Somewhere
  • /pgfplots/table/create col/set list={(math image)comma-separated-list(math image)}

  • A style for use in column creation context which creates a new column consisting of the entries in (math image)comma-separated-list(math image). The value is written as string (verbatim).

    The (math image)comma-separated-list(math image) is processed via TikZ’s \foreach command, that means you can use ... expressions to provide number (or character) ranges.

    (image)

    \pgfplotstableset{ create on use/my new col/.style={ create col/set list={A,B,C,4,50,55,...,100}}, columns/my new col/.style={string type} } \pgfplotstabletypeset[ columns={level,my new col}, ]{pgfplotstable.example1.dat}

    The new column will be padded or truncated to the required number of rows. If the list does not contain enough elements, empty cells will be produced.

  • /pgfplots/table/create col/copy column from table={(math image)file name or \macro(math image)}{(math image)column name(math image)}

  • A style for use in column creation context which creates a new column consisting of the entries in (math image)column name(math image) of the provided table. The argument may be either a file name or an already loaded table (i.e. a (math image)\macro(math image) as returned by \pgfplotstableread).

    You can use this style, possibly combined with \pgfplotstablenew, to merge one common sort of column from different tables into one large table.

    The cell values are written as string (verbatim).

    The new column will be padded or truncated to the required number of rows. If the list does not contain enough elements, empty cells will be produced.

6.3.3.2Mathematical Operations
  • /pgf/fpu=true|false (initially true)

  • Before we start to describe the column generation methods, one word about the math library. The core is always the pgf math engine written by Mark Wibrow and Till Tantau. However, this engine has been written to produce graphics and is not suitable for scientific computing.

    I added a high-precision floating point library to pgf which will be part of releases newer than pgf \(2.00\). It offers the full range of IEEE double precision computing in . This FPU is also part of PgfplotsTable, and it is activated by default for create col/expr and all other predefined mathematical methods.

    The FPU won’t be active for newly defined numerical styles (although it is active for the predefined mathematical expression parsing styles like create col/expr). If you want to add own routines or styles, you will need to use

    \pgfkeys{/pgf/fpu=true}

    in order to activate the extended precision. The standard math parser is limited to fixed point numbers in the range of \(\pm 16384.00000\).

Accumulated columns:

The expr style initializes \pgfmathaccuma to 0 before its first column. Whenever it computes a new column value, it redefines \pgfmathaccuma to be the result. That means you can use \pgfmathaccuma inside of (math image)math expression(math image) to accumulate columns. See create col/expr accum for more details.

About the precision and number range:

Starting with version 1.2, expr uses a floating point unit. The FPU provides the full data range of scientific computing with a relative precision between \(10^{-4}\) and \(10^{-6}\). The /pgf/fpu key provides some more details.

Accepted operations:

The math parser of pgf, combined with the FPU, provides the following function and operators:

+, -, *, /, abs, round, floor, mod, <, >, max, min, sin, cos, tan, deg (conversion from radians to degrees), rad (conversion from degrees to radians), atan, asin, acos, cot, sec, cosec, exp, ln, sqrt, the constanst pi and e, ^ (power operation), factorial107, rand (random between \(-1\) and \(1\) following a uniform distribution), rnd (random between \(0\) and \(1\) following a uniform distribution), number format conversions hex, Hex, oct, bin and some more. The math parser has been written by Mark Wibrow and Till Tantau, the FPU routines have been developed as part of pgfplots. The documentation for both parts can be found in the PGF/TikZ manual. Attention: Trigonometric functions work with degrees, not with radians, unless trig format is reconfigured!

  • /pgfplots/table/create col/quotient={(math image)column name(math image)}

  • A style for use in \pgfplotstablecreatecol which computes the quotient \(c_i := m_{i-1} / m_i\) for every entry \(i = 1,\dotsc , (n-1)\) in the column identified with (math image)column name(math image). The first value \(c_0\) is kept empty.

    (image)

    % requires \usepackage{array} \pgfplotstableset{% configuration, for example, in preamble: create on use/quot1/.style={create col/quotient=error1}, create on use/quot2/.style={create col/quotient=error2}, columns={error1,error2,quot1,quot2}, % % display styles: columns/error1/.style={sci,sci zerofill}, columns/error2/.style={sci,sci zerofill}, columns/quot1/.style={dec sep align}, columns/quot2/.style={dec sep align} } \pgfplotstabletypeset{pgfplotstable.example1.dat}

    This style employs methods of the floating point unit, that means it works with a relative precision of about \(10^{-7}\) (\(7\) significant digits in the mantissa).

  • /pgfplots/table/create col/iquotient={(math image)column name(math image)}

  • Like create col/quotient, but the quotient is inverse.

  • /pgfplots/table/create col/dyadic refinement rate={(math image)column name(math image)}

  • A style for use in \pgfplotstablecreatecol which computes the convergence rate \(\alpha \) of the data in column (math image)column name(math image). The contents of (math image)column name(math image) is assumed to be something like \(e_i(h_i) = O(h_i^\alpha )\). Assuming a dyadic refinement relation from one row to the next, \(h_i = h_{i-1}/2\), we have \(h_{i-1}^\alpha / (h_{i-1}/2)^\alpha = 2^\alpha \), so we get \(\alpha \) using

    \[ c_i := \log _2\left ( \frac {e_{i-1}}{e_i} \right ). \]

    The first value \(c_0\) is kept empty.

    (image)

    % requires \usepackage{array} \pgfplotstabletypeset[% here, configuration options apply only to this single statement: create on use/rate1/.style={create col/dyadic refinement rate={error1}}, create on use/rate2/.style={create col/dyadic refinement rate={error2}}, columns={error1,error2,rate1,rate2}, columns/error1/.style={sci,sci zerofill}, columns/error2/.style={sci,sci zerofill}, columns/rate1/.style={dec sep align}, columns/rate2/.style={dec sep align}] {pgfplotstable.example1.dat}

    This style employs methods of the floating point unit, that means it works with a relative precision of about \(10^{-6}\) (\(6\) significant digits in the mantissa).

  • /pgfplots/table/create col/gradient={(math image)col x(math image)}{(math image)col y(math image)}

  • /pgfplots/table/create col/gradient loglog={(math image)col x(math image)}{(math image)col y(math image)}

  • /pgfplots/table/create col/gradient semilogx={(math image)col x(math image)}{(math image)col y(math image)}

  • /pgfplots/table/create col/gradient semilogy={(math image)col x(math image)}{(math image)col y(math image)}

  • A style for \pgfplotstablecreatecol which computes piecewise gradients \((y_{i+1} - y_i) / (x_{i+1} - x_i )\) for each row. The \(y\) values are taken out of column (math image)col y(math image) and the \(x\) values are taken from (math image)col y(math image).

    The logarithmic variants apply the natural logarithm, \(\log (\cdot )\), to its argument before starting to compute differences. More precisely, the loglog variant applies the logarithm to both \(x\) and \(y\), the semilogx variant applies the logarithm only to \(x\) and the semilogy variant applies the logarithm only to \(y\).

    (image)

    % requires \usepackage{array} \pgfplotstableset{% configuration, for example in preamble: create on use/slopes1/.style={create col/gradient loglog={dof}{error1}}, create on use/slopes2/.style={create col/gradient loglog={dof}{error2}}, columns={dof,error1,error2,slopes1,slopes2}, % display styles: columns/dof/.style={int detect}, columns/error1/.style={sci,sci zerofill}, columns/error2/.style={sci,sci zerofill}, columns/slopes1/.style={dec sep align}, columns/slopes2/.style={dec sep align} } \pgfplotstabletypeset{pgfplotstable.example1.dat}

    (image)

    % requires \usepackage{array} \pgfplotstableset{% configuration, for example in preamble: create on use/slopes1/.style={create col/gradient semilogy={level}{error1}}, columns={level,error1,slopes1}, % display styles: columns/level/.style={int detect}, columns/error1/.style={sci,sci zerofill,sci subscript}, columns/slopes1/.style={dec sep align} } \pgfplotstabletypeset{pgfplotstable.example1.dat}

    This style employs methods of the floating point unit, that means it works with a relative precision of about \(10^{-6}\) (\(6\) significant digits in the mantissa).

  • /pgfplots/table/create col/linear regression={(math image)key-value-config(math image)}

  • Computes a linear (least squares) regression \(y(x) = a \cdot x + b\) using the sample data \((x_i,y_i)\) which has to be specified inside of (math image)key-value-config(math image).

    (image)

    % load table from somewhere: \pgfplotstableread{ x y 1 1 2 4 3 9 4 16 5 25 6 36 }\loadedtbl % create the `regression' column: \pgfplotstablecreatecol[linear regression] {regression} {\loadedtbl} % store slope \xdef\slope{\pgfplotstableregressiona} \pgfplotstabletypeset\loadedtbl\\ The slope is `\slope'.

    The example above loads a table from inline data, appends a column named ‘regression’ and typesets it. Since no (math image)key-value-config(math image) has been provided, x=[index]0 and y=[index]1 will be used. The \xdef\slope{...} command stores the ‘\(a\)’ value of the regression line into a newly defined macro ‘\slope’.108

    The complete documentation for this feature has been moved to pgfplots due to its close relation to plotting. Please refer to the pgfplots manual coming with this package.

  • /pgfplots/table/create col/function graph cut y={(math image)cut value(math image)}{(math image)common options(math image)}{(math image)one key–value set for each plot(math image)}

  • A specialized style for use in create on use statements which computes cuts of (one or more) discrete plots \(y(x_1), \dotsc , y(x_N)\) with a fixed (math image)cut value(math image). The \(x_i\) are written into the table’s cells.

    In a cost–accuracy plot, this feature allows to extract the cost for fixed accuracy. The dual feature with cut x allows to compute the accuracy for fixed cost.

    (image)

    % Preamble: \pgfplotsset{width=7cm,compat=1.18} \pgfplotstablenew[ create on use/cut/.style={create col/function graph cut y= {2.5e-4} % search for fixed L2 = 2.5e-4 {x=Basis,y=L2,ymode=log,xmode=log} % double log, each function is L2(Basis) % now, provide each single function f_i(Basis): {{table=plotdata/newexperiment1.dat},{table=plotdata/newexperiment2.dat}} }, columns={cut}] {2} \loadedtable % Show the data: \pgfplotstabletypeset{\loadedtable} \begin{tikzpicture} \begin{loglogaxis} \addplot table[x=Basis,y=L2] {plotdata/newexperiment1.dat}; \addplot table[x=Basis,y=L2] {plotdata/newexperiment2.dat}; \draw[blue!30!white] (1,2.5e-4) -- (1e5,2.5e-4); \node[pin=-90:{$x=53.66$}] at (53.66,2.5e-4) {}; \node[pin=45:{$x=601.83$}] at (601.83,2.5e-4) {}; \end{loglogaxis} \end{tikzpicture}

    In the example above, we are searching for \(x_1\) and \(x_2\) such that \(f_1(x_1) = 2.5\cdot 10^{-4}\) and \(f_2(x_2) =2.5\cdot 10^{-4}\). On the left is the automatically computed result. On the right is a problem illustration with proper annotation using pgfplots to visualize the results. The (math image)cut value(math image) is set to 2.5e-4. The (math image)common options(math image) contain the problem setup; in our case logarithmic scales and column names. The third argument is a comma-separated-list. Each element \(i\) is a set of keys describing how to get \(f_i(\cdot )\).

    During both (math image)common options(math image) and (math image)one key–value set for each plot(math image), the following keys can be used:

    • table={(math image)table file or \macro(math image)}: either a file name or an already loaded table where to get the data points,

    • x={(math image)col name(math image)}: the column name of the \(x\)-axis,

    • y={(math image)col name(math image)}: the column name of the \(y\)-axis.

    • foreach={(math image)\foreach loop head(math image)}{(math image)file name pattern(math image)} This somewhat advanced syntax allows to collect tables in a loop automatically:

      (image)

      \pgfplotstablenew[ % same as above... create on use/cut/.style={create col/function graph cut y= {2.5e-4}% search for fixed L2 = 2.5e-4 {x=Basis,y=L2,ymode=log,xmode=log, foreach={\i in {1,2}}{plotdata/newexperiment\i.dat}}% {}% just leave this empty. }, columns={cut}] {2} \loadedtable % Show the data: \pgfplotstabletypeset{\loadedtable}

      PgfplotsTable will call \foreach (math image)\foreach loop head(math image) and it will expand (math image)file name pattern(math image) for every iteration. For every iteration, a simpler list entry of the form

      table={(math image)expanded pattern(math image)},x={(math image)value of x(math image)},y={(math image)value of y(math image)}

      will be generated.

      It is also possible to provide foreach= inside of (math image)one key–value set for each plot(math image). The foreach key takes precedence over table. Details about the accepted syntax of \foreach can be found in the pgf manual.

    The keys xmode and ymode can take either log or linear. All mentioned keys have the common key path

    /pgfplots/table/create col/function graph cut/.

  • /pgfplots/table/create col/function graph cut x={(math image)cut value(math image)}{(math image)common options(math image)}{(math image)one key–value set for each plot(math image)}

  • As above, just with \(x\) and \(y\) exchanged.

107 Starting with pgf versions newer than \(2.00\), you can use the postfix operator ! instead of factorial.

108 The \xdef means “global expanded definition”: it expands the argument until it can’t be expanded any further and assigns a (global) name to the result. See any book for details.