summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/pgfplots/pgfplotstable.tex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/doc/latex/pgfplots/pgfplotstable.tex')
-rw-r--r--Master/texmf-dist/doc/latex/pgfplots/pgfplotstable.tex672
1 files changed, 607 insertions, 65 deletions
diff --git a/Master/texmf-dist/doc/latex/pgfplots/pgfplotstable.tex b/Master/texmf-dist/doc/latex/pgfplots/pgfplotstable.tex
index 581b033cfcb..15d4668102b 100644
--- a/Master/texmf-dist/doc/latex/pgfplots/pgfplotstable.tex
+++ b/Master/texmf-dist/doc/latex/pgfplots/pgfplotstable.tex
@@ -2,7 +2,7 @@
%
% Package pgfplots.sty documentation.
%
-% Copyright 2007/2008 by Christian Feuersaenger.
+% Copyright 2007-2009 by Christian Feuersaenger.
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
@@ -36,6 +36,35 @@
tabsize=4,
}
+\makeatletter
+\pgfkeys{%
+ /codeexample/prettyprint/key name with handler/.code 2 args={%
+ \gdef\pgfplotstablemanualautocheck{}%
+ \foreach \special in {columns,create on use,alias,display columns}{%
+ \expandafter\pgfutil@in@\expandafter{\special/}{#1}%
+ \ifpgfutil@in@
+ \xdef\pgfplotstablemanualautocheck{\special}%
+ \breakforeach
+ \fi
+ }%
+ \ifx\pgfplotstablemanualautocheck\pgfutil@empty%
+ \pgfmanualpdfref{#1}{#1}/\pgfmanualpdfref{/handlers/#2}{#2}%
+ \else
+ \expandafter\def\expandafter\temp\expandafter##\expandafter1\pgfplotstablemanualautocheck/##2\relax{%
+ \pgfmanualpdfref
+ {/pgfplots/table/\pgfplotstablemanualautocheck}%
+ {##1\pgfplotstablemanualautocheck/}%
+ ##2/%
+ \pgfmanualpdfref{/handlers/#2}{#2}%
+ }%
+ \temp#1\relax
+ \fi
+ },
+ /pdflinks/search key prefixes in/.add={/pgf/number format/,}{,/pgfplots/table/create col/},
+ /pdflinks/show labels=false,
+}
+\makeatother
+
%\pgfplotstableset{debug=true}
\title{%
@@ -80,7 +109,7 @@ It is used with
\end{enumerate}
Both ways are shown in the examples below.
- Knowledge of |pgfkeys| is useful for a deeper insight into this package, as |.style|, |.append style| etc. are specific to |pgfkeys|. Please refer to the \PGF\ manual,~\cite[section pgfkeys]{tikz} if you want a deeper insight into |pgfkeys|. Otherwise, simply skip over to the examples provided in this document.
+ Knowledge of |pgfkeys| is useful for a deeper insight into this package, as |/.style|, |/.append style| etc. are specific to |pgfkeys|. Please refer to the \PGF\ manual,~\cite[section pgfkeys]{tikz} if you want a deeper insight into |pgfkeys|. Otherwise, simply skip over to the examples provided in this document.
You will find key prefixes |/pgfplots/table/| and |/pgf/number format/|. These prefixes can be skipped if they are used in \PGFPlotstable; they belong to the ``default key path'' of |pgfkeys|.
\end{command}
@@ -121,6 +150,8 @@ There is future support for a second header line which must start with `|$flags
\begin{codeexample}[]
\pgfplotstableset{% global config, for example in the preamble
+ % these columns/<colname>/.style={<options>} things define a style
+ % which applies to <colname> only.
columns/dof/.style={int detect,column type=r,column name=\textsc{Dof}},
columns/error1/.style={
sci,sci zerofill,sci sep align,precision=1,sci superscript,
@@ -152,7 +183,7 @@ There is future support for a second header line which must start with `|$flags
]
{pgfplotstable.example1.dat}
\end{codeexample}
-\noindent All of these options are explained in the following sections.
+\noindent All of these options are explained in all detail in the following sections.
Technical note: every opened file will be protocolled into your log file.
\end{command}
@@ -170,15 +201,12 @@ Technical note: every opened file will be protocolled into your log file.
\hspace{2cm}
\pgfplotstabletypeset[columns={dof,error2}]\table
\end{codeexample}
+ There are variants of this command which do not really built up a struct but which report every line to a ``listener''. There is also a struct which avoids protection by \TeX\ scopes. In case you need such things, consider reading the source code comments.
Technical note: every opened file will be protocolled into your log file.
\end{command}
-\begin{command}{\pgfplotstablegetrowsof\marg{file name or \textbackslash loadedtable}}
- Defines |\pgfmathresult| to be the number of rows in a table. The argument may be either a file name or an already loaded table (the \meta{\textbackslash macro} of |\pgfplotstableread|).
-\end{command}
-
-\begin{key}{/pgfplots/table/col sep=\mchoice{space,comma,semicolon,colon,braces} (initially space)}
+\begin{key}{/pgfplots/table/col sep=\mchoice{space,tab,comma,semicolon,colon,braces} (initially space)}
Specifies the column separation character for table reading. The initial choice, |space| means ``at least one white space''. White spaces are tab stops or spaces (newlines always delimit lines).
For example, the file |pgfplotstable.example1.csv| uses commas as separation characters.
@@ -204,20 +232,26 @@ level,dof,error1,error2,info,{grad(log(dof),log(error2))},quot(error1)
You may call |\pgfplotstableset{col sep=comma}| once in your preamble if all your tables use commas as column separator.
Please note that if cell entries (for example column names) contain the separation character, you need to enclose the column entry in \emph{braces}: |{grad(log(dof),log(error2)}|. If you want to use unmatched braces, you need to write a backslash before the brace. For example the name `|column{withbrace|' needs to be written as `|column\{withbrace|'.
+
+ For |col sep|$\neq$|space|, spaces will be considered to be part of the argument (there is no trimming). However, (as usual in \TeX), multiple successive spaces and tabs are summarized into white space. Of course, if |col sep=tab|, tabs are the column separators and will be treated specially.
Furthermore, if you need empty cells in case |col sep=space|, you have to provide |{}| to delimit such a cell since |col sep=space| uses \emph{at least} one white space (consuming all following ones).
The value |col sep=braces| is special since it actually uses two separation characters. Every single cell entry is delimited by an opening and a closing brace, \marg{entry}, for this choice. Furthermore, any white spaces (spaces and tabs) between cell entries are \emph{skipped} in case |braces| until the next \marg{entry} is found.
+
+ A further speciality of |col sep=braces| is that it has support for \emph{multi-line} cells: everything within balanced braces is considered to be part of a cell. This includes newlines\footnote{This treatment of newlines within balanced braces actually applies to every other column separator as well (it is a \TeX\ readline feature). In other words: you \emph{can} have multi line cells for every column separator if you enclose them in balanced curly braces. However, \texttt{col sep=braces} has the special treatment that end-of-line counts as white space character; for every other \texttt{col sep} value, this white space is suppressed to remove spurious spaces.}.
\end{key}
-\begin{key}{/pgfplots/table/header=\marg{boolean} (initially true)}
- Configures if column names shall be identified during input operations.
+\begin{key}{/pgfplots/table/header=\mchoice{true,false,has colnames} (initially true)}
+ Configures if column names shall be identified automatically during input operations.
- The `header' is the first non-comment line, but only if this line contains non-numerical entries. If the first non-comment line contains at least one non-numerical entry (for example `|a name|'), each entry in this line is supposed to be a column name.
+ The first non-comment line \emph{can} be a header which contains column names. The |header| key configures how to detect if that is really the case.
+
+ The choice \declaretext{true} enables auto--detection of column names: If the first non-comment line contains at least one non-numerical entry (for example `|a name|'), each entry in this line is supposed to be a column name. If the first non-comment line contains only numerical data, it is used as data row. In this case, column indices will be assigned as column ``names''.
- If the first non-comment line contains only numerical data, it is used as data row. In this case, column indices will be assigned as column ``names''.
+ The choice \declaretext{false} is identical to this last case, i.e.\ even if the first line contains strings, they won't be recognised as column names.
- Use |header=false| to force this last case, i.e. even if the first line contains strings, they won't be recognised as column names.
+ Finally, the choice \declaretext{has colnames} is the opposite of |false|: it assumes that the first non--comment line \emph{contains} column names. In other words: even if only numbers are contained in the first line, they are considered to be column \emph{names}.
\end{key}
\subsection{Selecting Columns}
@@ -228,16 +262,20 @@ level,dof,error1,error2,info,{grad(log(dof),log(error2))},quot(error1)
\begin{codeexample}[]
\pgfplotstabletypeset[columns={dof,level,[index]4}]{pgfplotstable.example1.dat}
\end{codeexample}
+
+ The special |pgfkeys| feature |\pgfplotstableset{columns/.add={}{,a further col}}| allows to \emph{append} a value, in this case `|,a further col|' to the actual value. See |/.add| for details.
\end{key}
\begin{pgfplotstablealiaskey}
- Assigns the new name \meta{new col name} for the column denoted by \meta{real col name}. Afterwards, accessing \meta{new col name} will use the data associated with column \meta{real col name}.
+ Assigns the new name \meta{col name} for the column denoted by \meta{real col name}. Afterwards, accessing \meta{col name} will use the data associated with column \meta{real col name}.
- You can use |columns/|\meta{new col name}|/.style| to assign styles for the alias, not for the original column name.
+ You can use |columns/|\meta{col name}|/.style| to assign styles for the alias, not for the original column name.
If there exists both an alias and a column of the same name, the column name will be preferred. Furthermore, if there exists a |create on use| statement with the same name, this one will also be preferred.
- In case \meta{new col name} contains characters which are required for key settings, you need to use braces around it: ``|alias/{name=wi/th,special}/.initial={othername}|''.
+ In case \meta{col name} contains characters which are required for key settings, you need to use braces around it: ``|alias/{name=wi/th,special}/.initial={othername}|''.
+
+ This key is used whenever columns are queries, it applies also to the |\addplot table| statement of \PGFPlots.
\end{pgfplotstablealiaskey}
\begin{pgfplotstablecolumnkey}
@@ -302,7 +340,7 @@ level,dof,error1,error2,info,{grad(log(dof),log(error2))},quot(error1)
If all column types are empty, the complete argument is skipped (assuming that no |tabular| environment is generated).
- Use |\pgfplotstableset{column type/.add=|\marg{before}\marg{after}|}| to \emph{modify} a value instead of overwriting it. The |.add| key handler works for other options as well.
+ Use |\pgfplotstableset{column type/.add=|\marg{before}\marg{after}|}| to \emph{modify} a value instead of overwriting it. The |/.add| key handler works for other options as well.
\begin{codeexample}[narrow]
\pgfplotstabletypeset[
columns={dof,error1,info},
@@ -312,6 +350,13 @@ level,dof,error1,error2,info,{grad(log(dof),log(error2))},quot(error1)
\end{codeexample}
\end{key}
+\begin{key}{/pgfplots/table/column name=\marg{\TeX\ display column name}}
+ Sets the column name in the current context.
+
+ It is advisable to provide this option inside of a column-specific style, i.e. using
+
+ |columns/|\marg{lowlevel colname}|/.style={column name=|\marg{\TeX\ display column name}|}| .
+\end{key}
\begin{codekey}{/pgfplots/table/assign column name}
Allows to \emph{modify} the value of |column name|.
@@ -334,8 +379,6 @@ level,dof,error1,error2,info,{grad(log(dof),log(error2))},quot(error1)
The first argument determines the alignment of the header column.
- The style |dec sep align| actually introduces two new |tabular| columns\footnote{Unfortunately, \texttt{dec sep align} is currently not very flexible when it comes to column type modifications. In particular, it is not possible to use colored columns or cells in conjunction with \texttt{dec sep align}. The \texttt{\textbackslash rowcolor} command works properly; the color hangover introduced by \texttt{colortbl} is adjusted automatically.}, namely |r@{}l|. It introduces multicolumns for column names accordingly and handles numbers which do not have a decimal separator.
-
Please note that you need |\usepackage{array}| for this style.
\begin{codeexample}[]
% requires \usepackage{array}
@@ -362,11 +405,60 @@ level,dof,error1,error2,info,{grad(log(dof),log(error2))},quot(error1)
]
{pgfplotstable.example1.dat}
\end{codeexample}
- It may be advisable to use the |zerofill| variants to force at least one digit after the decimal separator.
+ It may be advisable to use |fixed zerofill| and/or |sci zerofill| to force at least one digit after the decimal separator to improve placement of exponents:
+\begin{codeexample}[]
+% requires \usepackage{array}
+\pgfplotstabletypeset[
+ use comma,
+ columns={dof,error1,error2,info,{grad(log(dof),log(error2))}},
+ columns/error1/.style={dec sep align,sci zerofill},
+ columns/error2/.style={sci,sci subscript,sci zerofill,dec sep align},
+ columns/info/.style={fixed,dec sep align},
+ columns/{grad(log(dof),log(error2))}/.style={fixed,dec sep align,fixed zerofill}
+]
+ {pgfplotstable.example1.dat}
+\end{codeexample}
+
+ The style |dec sep align| actually introduces two new |tabular| columns\footnote{Unfortunately, \texttt{dec sep align} is currently not very flexible when it comes to column type modifications. In particular, it is not possible to use colored columns or cells in conjunction with \texttt{dec sep align}. The \texttt{\textbackslash rowcolor} command works properly; the color hangover introduced by \texttt{colortbl} is adjusted automatically.}, namely |r@{}l|. It introduces multicolumns for column names accordingly and handles numbers which do not have a decimal separator.
+
+
+ Note that for fixed point numbers, it might be an alternative to use |fixed zerofill| combined with |column type=r| to get a similar effect.
Please note that this style overwrites |column type|, |assign cell content| and some number formatting settings.
\end{stylekey}
+%--------------------------------------------------
+% FIXME : doesn't really work as intended:
+% \begin{stylekey}{/pgfplots/table/dec sep align/no unbounded}
+% Changes the internal processing of |dec sep align| such that unbounded values like $NaN$ and $\pm \infty$ will be aligned in exactly the same way as the column name.
+%
+% This avoids funny spacing around unbounded coordinates when used with |dec sep align|.
+
+% NO GALLERY
+% \begin{codeexample}[]
+% \pgfplotstabletypeset{pgfplotstable.example4.dat}
+% \vrule
+%
+% \pgfplotstabletypeset[
+% columns/b/.style={fixed,precision=1},
+% ]
+% {pgfplotstable.example4.dat}
+% \vrule
+%
+% \pgfplotstabletypeset[
+% columns/b/.style={fixed,precision=1,dec sep align},
+% ]
+% {pgfplotstable.example4.dat}
+% \vrule
+%
+% \pgfplotstabletypeset[
+% columns/b/.style={fixed,precision=1,dec sep align,dec sep align/no unbounded},
+% ]
+% {pgfplotstable.example4.dat}
+% \end{codeexample}
+% \end{stylekey}
+%--------------------------------------------------
+
\begin{stylekey}{/pgfplots/table/sci sep align=\marg{header column type} (initially c)}
A style which aligns numerical columns at the exponent in scientific representation.
@@ -454,6 +546,9 @@ A style which is installed for every column with odd column index (starting with
\begin{command}{\pgfplotstablecol}
During the evaluation of row or column options, this command expands to the current columns' index.
\end{command}
+\begin{command}{\pgfplotstablecolname}
+ During the evaluation of column options, this command expands to the current column's name. It is valid while |\pgfplotstabletypeset| processes the column styles (including the preprocessing step explained in section~\ref{sec:pgfplotstable:preproc}), prepares the output cell content and checks row predicates.
+\end{command}
\label{pgfplotstable:page:tablerow}
\begin{command}{\pgfplotstablerow}
During the evaluation of row or column options, this command expands to the current rows' index.
@@ -466,6 +561,15 @@ A style which is installed for every column with odd column index (starting with
During evaluation of \emph{rows}, this command expands to the total number of \emph{output} rows.
\end{command}
+\begin{command}{\pgfplotstablename}
+ During |\pgfplotstabletypeset|, this macro contains the table's macro name as top-level expansion. If you are unfamiliar with ``top-level-expansions'' and `|\expandafter|', you will probably never need this macro.
+
+ Advances users may benefit from expressions like
+
+ |\expandafter\pgfplotstabletypeset\pgfplotstablename|.
+
+ For tables which have been loaded from disk (and have no explicitly assigned macro name), this expands to a temporary macro.
+\end{command}
\subsection{Configuring Row Appearance}
@@ -572,10 +676,12 @@ The following styles allow to configure the final table code \emph{after any cel
\begin{key}{/pgfplots/table/begin table=\marg{code} (initially \textbackslash begin\{tabular\})}
Contains \marg{code} which is generated as table start.
+
+ Use |begin table/.add={}{[t]}| to append the prefix |[t]|.
\end{key}
\begin{codekey}{/pgfplots/table/typeset cell}
- A code key which assigns |/pgfplots/table/@cell content| to the final output of the current cell.
+ A code key which assigns \declareandlabel{/pgfplots/table/@cell content} to the final output of the current cell.
The first argument, |#1|, is the final cell's value. After this macro, the value of |@cell content| will be written to the output.
@@ -587,7 +693,7 @@ The following styles allow to configure the final table code \emph{after any cel
\pgfkeyssetvalue{/pgfplots/table/cell content}{#1&}%
\fi
\end{codeexample}
- \paragraph{Attention:} The value of |\pgfplotstablecol| is now in the range $1,\dotsc,n$ where $n=$ |\pgfplotstablecols|. This simplifies checks whether we have the last column.
+ \paragraph{Attention:} The value of |\pgfplotstablecol| starts with $1$ in this context, i.e.\ it is in the range $1,\dotsc,n$ where $n=$ |\pgfplotstablecols|. This simplifies checks whether we have the last column.
\end{codekey}
\begin{key}{/pgfplots/table/end table=\marg{code} (initially \textbackslash end\{tabular\})}
@@ -615,7 +721,13 @@ The command |\pgfutilensuremath| checks whether math mode is active and switches
\begin{codeexample}[code only]
\pgfplotstableset{include outfiles} % for example in the document's preamble
\end{codeexample}
- This allows to place any corrections manually into generated output files.
+ This allows to place any corrections manually into generated output files since \PGFPlotstable\ won't overwrite the resulting tables automatically.
+
+ This will affect tables for which the |outfile| option is set. If you wish to apply it to every table, consider
+\begin{codeexample}[code only]
+\pgfplotstableset{every table/.append style={outfile={#1.out}}}
+\end{codeexample}
+ \noindent which will generate an |outfile| name for every table.
\end{key}
\begin{key}{/pgfplots/table/force remake=\marg{boolean} (initially false)}
If enabled, the effect of |include outfiles| is disabled. As all key settings only last until the next brace (or |\end|\meta{}), this key can be used to re-generate some output files while others are still included.
@@ -623,6 +735,8 @@ The command |\pgfutilensuremath| checks whether math mode is active and switches
\begin{key}{/pgfplots/table/write to macro=\marg{\textbackslash macroname}}
If the value of |write to macro| is not empty, the completely generated (tabular) code will be written into the macro \marg{\textbackslash macroname}.
+
+ See the |typeset=false| key in case you need \emph{only} the resulting macro.
\end{key}
\begin{key}{/pgfplots/table/skip coltypes=\mchoice{true,false} (initially false)}
@@ -1089,7 +1203,7 @@ The main idea is to select one typesetting algorithm (for example ``format my nu
This first step to typeset a table involves the obvious input operations. Furthermore, the ``new column creation'' operations explained in section~\ref{pgfplotstable:createcol} are processed at this time. The table data is read (or acquired) as already explained earlier in this manual. Then, if columns are missing, column alias and |create on use| specifications will be processed as part of the loading procedure. See section~\ref{pgfplotstable:createcol} for details about column creation.
\subsection{Typesetting Cell Content}
-Typesetting cells means to take their value and ``do something''. In many cases, this involves number formatting routines. For example, the ``raw'' input data |12.56| might become |1.235| |\cdot| |10^1|. The result of this stage is no longer useful for content-based computations. The typesetting step follows the preprocessing step.
+Typesetting cells means to take their value and ``do something''. In many cases, this involves number formatting routines. For example, the ``raw'' input data |12.56| might become |1.26| |\cdot| |10^1|. The result of this stage is no longer useful for content-based computations. The typesetting step follows the preprocessing step.
\begin{codekey}{/pgfplots/table/assign cell content}
Allows to redefine the algorithm which assigns cell contents. The argument |#1| is the (unformatted) contents of the input table.
@@ -1104,13 +1218,13 @@ Typesetting cells means to take their value and ``do something''. In many cases,
\end{codekey}
\begin{key}{/pgfplots/table/assign cell content as number}
- This here is the default implementation of |assign cell contents|.
+ This here is the default implementation of |assign cell content|.
It invokes |\pgfmathprintnumberto| and writes the result into |@cell content|.
\end{key}
\begin{stylekey}{/pgfplots/table/string type}
- A style which redefines |assign cell contents| to simply return the ``raw'' input data, that means as text column. This assumes input tables with valid \LaTeX\ content (verbatim printing is not supported).
+ A style which redefines |assign cell content| to simply return the ``raw'' input data, that means as text column. This assumes input tables with valid \LaTeX\ content (verbatim printing is not supported).
\end{stylekey}
\begin{stylekey}{/pgfplots/table/date type=\marg{date format}}% (initially \year-\month-\day)}
@@ -1121,10 +1235,22 @@ Typesetting cells means to take their value and ``do something''. In many cases,
% \usepackage{pgfcalendar}
\pgfplotstableset{columns={date,account1}}
+% plotdata/accounts.dat contains:
+%
+% date account1 account2 account3
+% 2008-01-03 60 1200 400
+% 2008-02-06 120 1600 410
+% 2008-03-15 -10 1600 410
+% 2008-04-01 1800 500 410
+% 2008-05-20 2300 500 410
+% 2008-06-15 800 1920 410
+
+% Show the contents in `string type':
\pgfplotstabletypeset[
columns/date/.style={string type}
]{plotdata/accounts.dat}
\hspace{1cm}
+% Show the contents in `date type':
\pgfplotstabletypeset[
columns/date/.style={date type={\monthname\ \year}}
]{plotdata/accounts.dat}
@@ -1167,22 +1293,23 @@ Typesetting cells means to take their value and ``do something''. In many cases,
The date feature is implemented using the \PGF\ calendar module. This module employs the package |translator| (if it is loaded). I don't have more detail yet, sorry. Please refer to \cite{tikz} for more details.
\subsection{Preprocessing Cell Content}
-The preprocessing step allows to change cell contents \emph{before} any typesetting routine (like number formatting) has been applied. The data is available in numerical format and math operations can be applied. Furthermore, cells can be erased depending on their numerical value. The preprocess step follows the data acquisition step (``loading step''). This means in particular that you can create (or copy) columns and apply operations on them.
+\label{sec:pgfplotstable:preproc}
+The preprocessing step allows to change cell contents \emph{before} any typesetting routine (like number formatting) has been applied. Thus, if tables contain numerical data, it is possible to apply math operations at this stage. Furthermore, cells can be erased depending on their numerical value. The preprocess step follows the data acquisition step (``loading step''). This means in particular that you can create (or copy) columns and apply operations on them.
\begin{codekey}{/pgfplots/table/preproc cell content}
- Allows to \emph{modify} the contents of cells \emph{before} |assign cell contents| is called.
+ Allows to \emph{modify} the contents of cells \emph{before} |assign cell content| is called.
- The semantics is as follows: before the preprocessor, |@cell content| contains the raw input data (or, maybe, the result of another preprocessor call). After the preprocessor, |@cell content| is filled with a -- possibly modified -- value. The resulting value is then used as input to |assign cell contents|.
+ The semantics is as follows: before the preprocessor, |@cell content| contains the raw input data (or, maybe, the result of another preprocessor call). After the preprocessor, |@cell content| is filled with a -- possibly modified -- value. The resulting value is then used as input to |assign cell content|.
- In the default settings, |assign cell contents| expects numerical input. So, the preprocessor is expected to produce numerical output.
+ In the default settings, |assign cell content| expects numerical input. So, the preprocessor is expected to produce numerical output.
- It is possible to provide multiple preprocessor directives using |.append code| or |.append style| key handlers.
+ It is possible to provide multiple preprocessor directives using |/.append code| or |/.append style| key handlers.
- In case you don't want (or need) stackable preprocessors, you can also use `|#1|' to get the raw input datum as it is found in the file.
+ In case you don't want (or need) stackable preprocessors, you can also use `|#1|' to get the raw input datum as it is found in the file. Furthermore, the key |@unprocessed cell content| will also contain the raw input datum.
\end{codekey}
\begin{stylekey}{/pgfplots/table/string replace=\marg{pattern}\marg{replacement}}
- Appends code to the current |preproc cell content| value which replace every occurence of \marg{pattern} with \marg{replacement}. No expansion is performed during this step; \marg{pattern} must match literally.
+ Appends code to the current |preproc cell content| value which replaces every occurence of \marg{pattern} with \marg{replacement}. No expansion is performed during this step; \marg{pattern} must match literally.
\begin{codeexample}[]
\pgfplotstabletypeset[columns={level,dof}]
{pgfplotstable.example1.dat}
@@ -1200,6 +1327,40 @@ The preprocessing step allows to change cell contents \emph{before} any typesett
Appends code to the current |preproc cell content| value which replaces every infinite number with the empty string. This clears any cells with $\pm \infty$ and NaN.
\end{stylekey}
+\begin{stylekey}{/pgfplots/table/preproc/expr=\marg{math expression}}
+ Appends code to the current |preproc cell content| value which evaluates \marg{math expression} for every cell. Arithmetics are carried out in floating point.
+
+ Inside of \marg{math expression}, use one of the following expressions to get the current cell's value.
+ \begin{itemize}
+ \item The string `|##1|' expands to the cell's content as it has been found in the input file, ignoring preceeding preprocessors.
+
+ This is usually enough.
+
+ \item The command |\thisrow|\marg{the currently processed column name} expands to the current cell's content. This will also include the results of preceeding preprocessors.
+
+ Note that |\thisrow{}| in this context (inside of the preprocessor) is not as powerful as in the context of column creation routines: the argument must match exactly the name of the currently processed column name. You can also use the shorthand
+
+ |\thisrow{\pgfplotstablecolname}|.
+
+ \item The command |\pgfkeysvalueof{/pgfplots/table/@cell content}| is the same.
+ \end{itemize}
+
+\begin{codeexample}[]
+\pgfplotstabletypeset[
+ columns={level},
+ columns/level/.style={
+ column name={$2\cdot \text{level}+4$},
+ preproc/expr={2*##1 + 4}
+ }
+]
+ {pgfplotstable.example1.dat}
+\end{codeexample}
+
+ Empty cells won't be processed, assuming that a math expression with an ``empty number'' will fail.
+
+ Note that there is also an |create col/expr| which is more powerful than |preproc/expr|.
+\end{stylekey}
+
\begin{stylekey}{/pgfplots/table/multiply with=\marg{real number}}
Appends code to the current |preproc cell content| value which multiplies every cell with \marg{real number}. Arithmetics are carried out in floating point.
\end{stylekey}
@@ -1245,7 +1406,7 @@ The preprocessing step allows to change cell contents \emph{before} any typesett
\begin{codekey}{/pgfplots/table/row predicate}
A boolean predicate which allows to select particular rows of the input table. The argument |#1| contains the current row's index (starting with~$0$, not counting comment lines or column names).
- The return value is assigned to the \TeX-if |\ifpgfplotstableuserow|. If the boolean is not changed, the return value is true.
+ The return value is assigned to the \TeX-if \declareandlabel{\ifpgfplotstableuserow}. If the boolean is not changed, the return value is true.
\begin{codeexample}[narrow]
% requires \usepackage{booktabs}
\pgfplotstabletypeset[
@@ -1262,7 +1423,7 @@ The preprocessing step allows to change cell contents \emph{before} any typesett
]
{pgfplotstable.example1.dat}
\end{codeexample}
- Please note that |row predicate| is applied \emph{before} any other option which affects row appearance. It is evaluated before |assign cell contents|. For example, the even/odd row styles refer to those rows for which the predicate returns |true|. In fact, you can use |row predicate| to truncate the complete table before it as actually processed.
+ Please note that |row predicate| is applied \emph{before} any other option which affects row appearance. It is evaluated before |assign cell content|. For example, the even/odd row styles refer to those rows for which the predicate returns |true|. In fact, you can use |row predicate| to truncate the complete table before it as actually processed.
During |row predicate|, the macro |\pgfplotstablerows| contains the total number of \emph{input} rows.
@@ -1311,34 +1472,60 @@ The preprocessing step allows to change cell contents \emph{before} any typesett
If the available number of rows is not dividable by \marg{part count}, the remaining entries are distributed equally among the first parts.
\end{stylekey}
+\begin{stylekey}{/pgfplots/table/unique=\marg{column name}}
+ A style which appends an |row predicate| which suppresses successive occurances of the same elements in \marg{column name}.
+ For example, if \marg{column name} contains |1,1,3,5,5,6,5,0|, the application of |unique| results in |1,3,5,6,5,0| (the last |5| is kept -- it is not directly preceeded by another |5|).
+
+ The algorithm uses string token comparison to find multiple occurances\footnote{To be more precise, the comparison is done using \texttt{\textbackslash ifx}, i.e. cell contents won't be expanded. Only the tokens as they are seen in the input table will be used.}.
+
+ The argument \marg{column name} can be a column name, index, alias, or |create on use| specification (the latter one must not depend on other |create on use| statements). It is not necessary to provide a \marg{column name} which is part of the output.
+
+ However, it \emph{is} necessary that the |unique| predicate can be evaluated for all columns, starting with the first one. That means it is an error to provide |unique| somewhere deep in column--specific styles.
+\end{stylekey}
\subsection{Postprocessing Cell Content}
The postprocessing step is applied after the typesetting stage, that means it can't access the original input data. However, it can apply final formatting instructions which are not content based.
\begin{codekey}{/pgfplots/table/postproc cell content}
- Allows to \emph{modify} assigned cell content \emph{after} it has been assigned, possibly content-dependend. Ideas could be to draw negative numbers in red, typeset single entries in bold face or insert replacement text.
+ Allows to \emph{modify} assigned cell content \emph{after} it has been assigned, possibly content-dependent. Ideas could be to draw negative numbers in red, typeset single entries in bold face or insert replacement text.
This key is evaluated \emph{after} |assign cell content|. Its semantics is to modify an existing |@cell content| value.
- There may be more than one |postproc cell content| command, if you use |.append code| or |.append style| to define them:
+ There may be more than one |postproc cell content| command, if you use |/.append code| or |/.append style| to define them:
\begin{codeexample}[]
% requires \usepackage{eurosym}
\pgfplotstabletypeset[
column type=r,
columns={dof,info},
columns/info/.style={
+ % stupid example for multiple postprocessors:
postproc cell content/.append style={
- /pgfplots/table/@cell content/.add={$\bf}{$}},
+ /pgfplots/table/@cell content/.add={$\bf}{$},
+ },
postproc cell content/.append style={
- /pgfplots/table/@cell content/.add={}{\EUR{}}}
+ /pgfplots/table/@cell content/.add={}{\EUR{}},
+ }
}]
{pgfplotstable.example1.dat}
\end{codeexample}
- The code above modifies |@cell content| successively. First, ``|$\bf ... $|'' is inserted, then ``|...\EUR|''. It should be noted that |pgfkeys| handles |.style| and |.code| in (quasi) the same way -- both are simple code keys and can be used as such. You can combine both with |.append style| and |.append code|. Please refer to~\cite[section about pgfkeys]{tikz} for details.
+ The code above modifies |@cell content| in two steps. The net effect is to prepend ``|$\bf |'' and to append ``|$ \EUR|''. It should be noted that |pgfkeys| handles |/.style| and |/.code| in (quasi) the same way -- both are simple code keys and can be used as such. You can combine both with |/.append style| and |/.append code|. Please refer to~\cite[section about pgfkeys]{tikz} for details.
+
+ As in |assign cell content|, the code can evaluate helper macros like |\pgfplotstablerow| to change only particular entries. Furthermore, the postprocessor may depend on the unprocessed cell input (as it has been found in the input file or produced by the loading procedure) and/or the preprocessed cell value. These values are available as
+ \begin{itemize}
+ \item the key \declareandlabel{@unprocessed cell content} which stores the raw input,
+ \item the key \declareandlabel{@preprocessed cell content} which stores the result of the preprocessor,
+ \item the key \declareandlabel{@cell content} which contains the result of the typesetting routine,
+ \item the shorthand `|#1|' which is also the unprocessed input argument as it has been found in the input table.
+ \end{itemize}
+ Remember that you can access the key values using
+
+ |\pgfkeysvalueof{/pgfplots/table/@preprocessed cell content}|
- As in |assign cell contents|, the code can evaluate helper macros like |\pgfplotstablerow| to change only particular entries. Furthermore, the argument ``|#1|'' expands to the \emph{unformatted} input argument which was found in the input table. This allows complete context based formatting options. Please remember that empty strings may appear due to column balancing -- introduce special treatment if necessary.
+ at any time.
+
+ This allows complete context based formatting options. Please remember that empty strings may appear due to column balancing -- introduce special treatment if necessary.
- There is one special case which occurs if |@cell content| itsself contains the cell separation character `|&|'. In this case, |postproc cell contents| is invoked \emph{separately} for each part before and after the ampersand and the ampersand is inserted afterwards. This allows compatibility with special styles which create artificial columns in the output (which is allowed, see |dec sep align|). To allow separate treatment of each part, you can use the macro |\pgfplotstablepartno|. It is defined only during the evaluation of |postproc cell content| and it evaluates to the current part index (starting with~$0$). If there is no ampersand in your text, the value will always be~$0$.
+ There is one special case which occurs if |@cell content| itsself contains the cell separation character `|&|'. In this case, |postproc cell content| is invoked \emph{separately} for each part before and after the ampersand and the ampersand is inserted afterwards. This allows compatibility with special styles which create artificial columns in the output (which is allowed, see |dec sep align|). To allow separate treatment of each part, you can use the macro \declareandlabel{\pgfplotstablepartno}. It is defined only during the evaluation of |postproc cell content| and it evaluates to the current part index (starting with~$0$). If there is no ampersand in your text, the value will always be~$0$.
This key is evaluated inside of a local \TeX\ group, so any local macro assignments will be cleared afterwards.
@@ -1370,23 +1557,59 @@ Since this may be useful in a more general context, it is available as |empty ce
\end{stylekey}
\begin{stylekey}{/pgfplots/table/set content=\marg{content}}
- A style which redefines |postproc cell contents| to always return the value \marg{content}.
+ A style which redefines |postproc cell content| to always return the value \marg{content}.
\end{stylekey}
+\begin{stylekey}{/pgfplots/table/fonts by sign=\marg{\TeX\ code for positive}\marg{\TeX\ code for negative}}
+ Appends code to |postproc cell content| which allows to set fonts for positive and negative numbers.
+
+ The arguments \meta{\TeX\ code for positive} and \meta{\TeX\ code for negative} are inserted right before the typesetted cell content. It is permissable to use both ways to change \LaTeX\ fonts: the |\textbf|\marg{argument} or the |{\bfseries |\marg{argument}|}| way.
+
+% \usepackage{pgfcalendar}
+\begin{codeexample}[]
+% Requires
+% \usepackage{pgfcalendar}
+
+% plotdata/accounts.dat contains:
+%
+% date account1 account2 account3
+% 2008-01-03 60 1200 400
+% 2008-02-06 120 1600 410
+% 2008-03-15 -10 1600 410
+% 2008-04-01 1800 500 410
+% 2008-05-20 2300 500 410
+% 2008-06-15 800 1920 410
+
+\pgfplotstabletypeset[
+ columns={date,account1},
+ column type=r,
+ columns/date/.style={date type={\monthname\ \year}},
+ columns/account1/.style={fonts by sign={}{\color{red}}}
+]
+ {plotdata/accounts.dat}
+\end{codeexample}
+ In fact, the arguments for this style don't need to be font changes. The style |fonts by sign| inserts several braces and the matching argument into |@cell content|. To be more precise, it results in
+
+ |{|\meta{\TeX\ code for negative}|{|\meta{cell value}|}}| for negative numbers and
+
+ |{|\meta{\TeX\ code for positive}|{|\meta{cell value}|}}| for all other numbers.
+\end{stylekey}
\section{Generating Data in New Tables or Columns}
\label{pgfplotstable:createcol}
It is possible to create new tables from scratch or to change tables after they have been loaded from disk.
\subsection{Creating New Tables From Scratch}
-\begin{command}{\pgfplotstablenew\oarg{options}\marg{row count}\marg{\textbackslash table}}
+\begin{commandlist}{%
+ \pgfplotstablenew\oarg{options}\marg{row count}\marg{\textbackslash table},%
+ \pgfplotstablenew*\oarg{options}\marg{row count}\marg{\textbackslash table}}
Creates a new table from scratch.
- The new table will contain all columns listed in the |columns| key
- which needs to be provided in \oarg{options}\footnote{Currently, you need to provide at least one column here: the implementation gets confused for completely empty tables. If you do not provide any column name, a dummy column will be created.}.
+ The new table will contain all columns listed in the |columns| key. For |\pgfplotstablenew|, the |columns| key needs to be provided in \oarg{options}. 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. Columns are generated
+ column which shall be generated\footnote{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.}. Columns are generated
independently, in the order of appearance in |columns|.
The table will contain exactly \marg{row count} rows. If \marg{row count} is an |\pgfplotstablegetrowsof| statement, that statement will be executed and the resulting number of rows be used. Otherwise, \marg{row count} will be evaluated as number.
@@ -1412,9 +1635,10 @@ It is possible to create new tables from scratch or to change tables after they
% show it:
\pgfplotstabletypeset\table
\end{codeexample}
-\end{command}
+\end{commandlist}
\begin{command}{\pgfplotstablevertcat\marg{\textbackslash table1}\marg{\textbackslash table2 or filename}}
+\label{table:vertcat}
Appends the contents of \marg{\textbackslash table2} to \marg{\textbackslash table1} (``vertical cat''). To be more precise, only columns which exist already in \marg{\textbackslash table1} will be appended and every column which exists in \marg{\textbackslash table1} must exist in \marg{\textbackslash table2} (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.
@@ -1425,6 +1649,21 @@ It is possible to create new tables from scratch or to change tables after they
\pgfplotstablevertcat{\output}{datafile2} % appends rows of datafile2
\pgfplotstablevertcat{\output}{datafile3} % appends rows of datafile3
\end{codeexample}
+
+ \paragraph{Remark:} The output table \marg{\textbackslash table1} will be defined in the current \TeX\ scope and it will be erased afterwards.
+ The current \TeX\ scope is delimited by an extra set of curly braces. However, every \LaTeX\ environment and, unfortunately, the \Tikz\ |\foreach| statement as well, introduce \TeX\ scopes.
+
+ \PGFPlots\ has some some loop statements which do not introduce extra scopes. For example,
+\begin{codeexample}[code only]
+\pgfplotsforeachungrouped \i in {1,2,...,10} {%
+ \pgfplotstablevertcat{\output}{datafile\i} % appends `datafile\i' -> `\output'
+}%
+\end{codeexample}
+ These looping macros are explained in the manual of \PGFPlots, reference section ``Miscellaneous Commands''
+\end{command}
+
+\begin{command}{\pgfplotstableclear\marg{\textbackslash table}}
+ 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).
\end{command}
\subsection{Creating New Columns From Existing Ones}
@@ -1437,8 +1676,8 @@ This command offers a flexible framework to generate new columns. It has been de
The following documentation is for all who want to \emph{write} specialised 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 \marg{options}.
-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|.
+The column entries will be created using the command key \pgfmanualpdflabel{/pgfplots/table/create col/assign}{\declaretext{create col/assign}}. It will be invoked for every row of the table.
+It is supposed to assign contents to \pgfmanualpdflabel{/pgfplots/table/create col/next content}{\declaretext{create col/next content}}.
During the evaluation, the macro |\thisrow|\marg{col name}
expands to the current row's value of the column identified by \marg{col name}.
Furthermore, |\nextrow|\marg{col name} expands to the \emph{next} row's
@@ -1446,26 +1685,32 @@ value of the designated column and |\prevrow|\marg{col name} expands to the valu
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 \emph{last} row is computed with |create col/assign last|. Its semantics is the same. The contents for the \emph{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.
+Two special |assign| routines are available for the first and last row: The contents for the \emph{last} row is computed with \pgfmanualpdflabel{/pgfplots/table/create col/assign last}{\declaretext{create col/assign last}}. Its semantics is the same. The contents for the \emph{first} row is computed with \pgfmanualpdflabel{/pgfplots/table/create col/assign first}{\declaretext{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 \TeX\ groups (i.e. any local definitions will be cleared afterwards).
The following macros are useful during cell assignments:
\begin{enumerate}
- \item |\prevrow|\marg{col name} / |\getprevrow|\marg{col name}\marg{\textbackslash macro}
+ \item \declareandlabel{\prevrow}\marg{col name} / \declareandlabel{\getprevrow}\marg{col name}\marg{\textbackslash macro}
These two routines return the value stored in the \emph{previous} row of the designated column \marg{col name}. The |get| routine stores it into \meta{\textbackslash macro}.
- \item |\thisrow|\marg{col name} / |\getthisrow|\marg{col name}\marg{\textbackslash macro}
+ The argument \meta{col name} has to denote either an existing column name or one for which an |alias/|\meta{col name} exists.
+
+ \item \declareandlabel{\thisrow}\marg{col name} / \declareandlabel{\getthisrow}\marg{col name}\marg{\textbackslash macro}
These two routines return the \emph{current} row's value stored in the designated column. The |get| routine stores it into \meta{\textbackslash macro}.
- \item |\nextrow|\marg{col name} / |\getnextrow|\marg{col name}\marg{\textbackslash macro}
+ The argument \meta{col name} has to denote either an existing column name or one for which an |alias/|\meta{col name} exists.
+
+ \item \declareandlabel{\nextrow}\marg{col name} / \declareandlabel{\getnextrow}\marg{col name}\marg{\textbackslash macro}
These two routines return the \emph{next} row's value.
+ The argument \meta{col name} has to denote either an existing column name or one for which an |alias/|\meta{col name} exists.
+
\item |\pgfplotstablerow| and |\pgfplotstablerows| which contain the current row's index and the total number of rows, respectively. See page~\pageref{pgfplotstable:page:tablerow} for details.
- \item |\pgfmathaccuma| and |\pgfmathaccumb| can be used to transport intermediate results.
+ \item \declareandlabel{\pgfmathaccuma} and \declareandlabel{\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 initialised by column creation styles.
\item 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.
\end{enumerate}
@@ -1493,7 +1738,9 @@ The following example takes our well-known input table and creates a copy of the
There is one more speciality: you can use |columns=|\marg{column list} to reduce the runtime complexity of this command. This works only if the |columns| key is provided directly into \marg{options}. In this case |\thisrow| and its variants are only defined for those columns listed in the |columns| value.
-\paragraph{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. Furthermore, this command has been designed to modify an existing table. You can't create a table from scratch with this command.
+\paragraph{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.
+
+\paragraph{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|.
\end{command}
@@ -1530,6 +1777,8 @@ The default implementation of |assign| is to produce empty strings. The default
In case \meta{col name} 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.
\end{pgfplotstablecreateonusekey}
\subsection{Predefined Column Generation Methods}
@@ -1595,13 +1844,13 @@ The following keys can be used in both |\pgfplotstablecreatecol| and the easier
\subsubsection{Mathematical Operations}
-\begin{key}{/pgf/fpu=\marg{true,false}}
+\begin{key}{/pgf/fpu=\mchoice{true,false} (initially true)}
\index{Precision}
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 \TeX. 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. If you want to add own routines or styles, you will need to use
+ 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
\begin{codeexample}[code only]
\pgfkeys{/pgf/fpu=true}
\end{codeexample}
@@ -1644,7 +1893,8 @@ The following keys can be used in both |\pgfplotstablecreatecol| and the easier
create on use/new/.style={
create col/expr={\pgfmathaccuma + \thisrow{level}}},
create on use/new2/.style={
- create col/expr accum={\pgfmathaccuma - \thisrow{level}}{100}}
+ create col/expr accum={\pgfmathaccuma * \thisrow{level}}{1}%<- start with `1'
+ }
}
\pgfplotstabletypeset[
@@ -1763,6 +2013,8 @@ The example creates two columns: the |new| column is just the sum of each value
columns={cut}]
{2}
\table
+
+% Show the data:
\pgfplotstabletypeset{\table}
\begin{tikzpicture}
@@ -1775,16 +2027,41 @@ The example creates two columns: the |new| column is just the sum of each value
\end{loglogaxis}
\end{tikzpicture}
\end{codeexample}
- In the example above, we are searching for $x_1$ and $x_2$ such that $f_1(x_1) = \pgfmathprintnumber{2.5e-4}$ and $f_2(x_2) =\pgfmathprintnumber{2.5e-4}$. On the left is the automatically computed result. On the right is a problem illustration with proper annotation.
+ In the example above, we are searching for $x_1$ and $x_2$ such that $f_1(x_1) = \pgfmathprintnumber{2.5e-4}$ and $f_2(x_2) =\pgfmathprintnumber{2.5e-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 \marg{cut value} is set to |2.5e-4|. The \marg{common options} 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, \marg{common options} and the key sets, the following keys can be used:
+ During both, \marg{common options} and \marg{one key-value set for each plot}, the following keys can be used:
\begin{itemize}
- \item |table|: either a file name or an already loaded table where to get the data points,
- \item |x|: the column name of the $x$ axis,
- \item |y|: the column name of the $y$ axis.
+ \item \declareandlabel{table}|=|\marg{table file or \textbackslash macro}: either a file name or an already loaded table where to get the data points,
+ \item \declareandlabel{x}|=|\marg{col name}: the column name of the $x$ axis,
+ \item \declareandlabel{y}|=|\marg{col name}: the column name of the $y$ axis.
+ \item \declareandlabel{foreach}|=|\marg{\textbackslash foreach loop head}\marg{file name pattern}
+ This somewhat advanced syntax allows to collect tables in a loop automatically:
+
+\begin{codeexample}[]
+\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}
+ \table
+% Show the data:
+\pgfplotstabletypeset{\table}
+\end{codeexample}
+ \PGFPlotstable\ will call |\foreach |\meta{\textbackslash foreach loop head} and it will expand \marg{file name pattern} for every iteration. For every iteration, a simpler list entry of the form
+
+ |table=|\marg{expanded pattern}|,x=|\marg{value of x}|,y=|\marg{value of y}
+
+ will be generated.
+
+ It is also possible to provide |foreach=| inside of \marg{one key-value set for each plot}. The |foreach| key takes precedence over |table|. Details about the accepted syntax of |\foreach| can be found in the \pgfname\ manual.
\end{itemize}
- The keys |xmode| and |ymode| can take either |log| or |linear|. All mentioned keys have the common key path
+ The keys \declareandlabel{xmode} and \declareandlabel{ymode} can take either |log| or |linear|. All mentioned keys have the common key path
\textcolor{red!75!black}{\texttt{/pgfplots/table/create col/function graph cut/}}.
\end{stylekey}
@@ -1851,10 +2128,275 @@ Empty cells will be filled with |{}| if |col sep=space|. Use the |empty cells wi
In case you want to reset all, you should also consider the key |disable rowcol styles|.
\end{key}
+\subsection{A summary of how to define and use styles and keys}
+This section summarizes features of |pgfkeys|. The complete documentation can be found in the \pgfname\ manual,~\cite{tikz}.
+\begin{handler}{{.style}=\marg{key-value-list}}
+ Defines or redefines a style \meta{key}. A style is a normal key which will set all options in \marg{key-value-list} when it is set.
+
+ Use |\pgfplotstableset{|\meta{key}|/.style={|\meta{key-value-list}|}}| to (re-) define a style \meta{key} in the namespace |/pgfplots/table|.
+\end{handler}
+
+\begin{handler}{{.append style}=\marg{key-value-list}}
+ Appends \marg{key-value-list} to an already existing style \meta{key}. This is the preferred method to change the predefined styles: if you only append, you maintain compatibility with future versions.
+
+ Use |\pgfplotstableset{|\meta{key}|/.append style={|\meta{key-value-list}|}}| to append \marg{key-value-list} to the style \meta{key}. This will assume the prefix |/pgfplots/table|.
+\end{handler}
+
+\begin{handler}{{.add}=\marg{before}\marg{after}}
+ Changes \meta{key} by prepending \meta{before} and appending \meta{after}.
+\begin{codeexample}[]
+\pgfplotstableset{columns={a column}}
+`\pgfkeysvalueof{/pgfplots/table/columns}';
+\pgfplotstableset{columns/.add={}{,another}}
+`\pgfkeysvalueof{/pgfplots/table/columns}';
+\pgfplotstableset{columns/.add={}{,and one more}}
+`\pgfkeysvalueof{/pgfplots/table/columns}'.
+\end{codeexample}
+ This can be used inside of |\pgfplotsinvokeforeach| or similar (ungrouped!) loop constructs.
+\end{handler}
+
+\begin{handler}{{.code}=\marg{\TeX\ code}}
+ Occasionally, the \PGFPlots\ user interface offers to replace parts of its routines. This is accomplished using so called ``code keys''. What it means is to replace the original key and its behavior with new \marg{\TeX\ code}. Inside of \marg{\TeX\ code}, any command can be used. Furthermore, the |#1| pattern will be the argument provided to the key.
+
+\begin{codeexample}[]
+\pgfplotsset{
+ My Code/.code={This is a pgfkeys feature. Argument=`#1'}}
+\pgfplotsset{My Code={is here}}
+\end{codeexample}
+ The example defines a (new) key named |My Code|. Essentially, it is nothing else but a |\newcommand|, plugged into the key-value interface. The second statement ``invokes'' the code key.
+\end{handler}
+
+\begin{handler}{{.append code}=\marg{\TeX\ code}}
+ Appends \marg{\TeX\ code} to an already existing |/.code| key named \meta{key}.
+\end{handler}
+
+
+\begin{handler}{{.code 2 args}=\marg{\TeX\ code}}
+ As |/.code|, but this handler defines a key which accepts two arguments. When the so defined key is used, the two arguments are available as |#1| and |#2|.
+\end{handler}
+
+
\subsection{Plain \TeX\ and Con\TeX t support}
\label{sec:pgfplotstable:context}
The table code generator is initialised to produce \LaTeX\ |tabular| environments. However, it only relies on~`|&|' being the column separator and~`|\\|' the row terminator. The |column type| feature is more or less specific to |tabular|, but you can disable it completely. Replace |begin table| and |end table| with appropriate \TeX- or Con\TeX t commands to change it. If you have useful default styles (or bug reports), let me know.
+\subsection{Basic Level Table Access and Modification}
+\PGFPlotstable\ provides several methods to access and manipulate tables at an elementary level.
+
+Please keep in mind that \PGFPlotstable\ has been written as tool for table visualization. As such, it has been optimized for the case of relatively few rows (although it may have a lot of columns). The runtime for table creation and modification is currently $O(N^2)$ where $N$ is the number of rows\footnote{The runtime for \texttt{plot table} is linear in the number of rows using a special routine.}. This is completely acceptable for tables with few rows because \TeX\ can handle those structures relatively fast. Keep your tables small! \PGFPlotstable\ is \emph{not} a tool for large-scale matrix operations.
+
+Tables are always stored as a sequence of column vectors. Therefore, iteration over all values in one column is simple whereas iteration over all values in one row is complicated and expensive.
+
+\begin{command}{\pgfplotstableforeachcolumn\meta{table}\textbackslash as\marg{\textbackslash macro}\marg{code}}
+ Iterates over every column name of \meta{table}. The \meta{\textbackslash macro} will be set to the currently visited column name. Then, \marg{code} will be executed. During \marg{code}, |\pgfplotstablecol| denotes the current column index (starting with 0).
+\begin{codeexample}[]
+\begin{minipage}{0.8\linewidth}
+\pgfplotstableread{pgfplotstable.example1.dat}\table
+\pgfplotstableforeachcolumn\table\as\col{%
+ column name is `\col'; index is\pgfplotstablecol;\par
+}
+\end{minipage}
+\end{codeexample}
+
+ This routine does not introduce \TeX\ groups, variables inside of \marg{code} are not scoped.
+\end{command}
+
+\begin{command}{\pgfplotstableforeachcolumnelement\meta{column name}\textbackslash of\meta{table}\textbackslash as\meta{\textbackslash cellcontent}\marg{code}}
+ Reports every table cell $t_{ij}$ for a fixed column $j$ in read-only mode.
+
+ For every cell in the column named \meta{column name}, \marg{code} will be executed. During this invocation, the macro \meta{\textbackslash cellcontent} will contain the cell's content and |\pgfplotstablerow| will contain the current row's index.
+\begin{codeexample}[]
+\begin{minipage}{0.8\linewidth}
+\pgfplotstableread{pgfplotstable.example1.dat}\table
+\pgfplotstableforeachcolumnelement{error1}\of\table\as\cell{%
+ I have now cell element `\cell' at row index `\pgfplotstablerow';\par
+}
+\end{minipage}
+\end{codeexample}
+ The argument \meta{column name} can also be a column index. In that case, it should contain |[index]|\meta{integer}, for example |[index]4|. Furthermore, column aliases and column which should be generated on-the-fly (see |create on use|) can be used for \meta{column name}.
+
+ This routine does not introduce \TeX\ groups, variables inside of \marg{code} are not scoped.
+\end{command}
+
+\begin{command}{\pgfplotstablemodifyeachcolumnelement\meta{column name}\textbackslash of\meta{table}\textbackslash as\meta{\textbackslash cellcontent}\marg{code}}
+ A routine which is similar to |\pgfplotstableforeachcolumnelement|,
+ but any changes of \meta{\textbackslash cellcontent} which might occur during \marg{code} will be written back into the respective cell.
+
+\begin{codeexample}[]
+\pgfplotstableread{pgfplotstable.example1.dat}\table
+\pgfplotstablemodifyeachcolumnelement{error1}\of\table\as\cell{%
+ \edef\cell{\#\pgfplotstablerow: \cell}%
+}
+\pgfplotstabletypeset[columns=error1,string type]{\table}
+\end{codeexample}
+
+ If \marg{column name} is a column alias or has been created on-the-fly, a new column named \meta{column name} will be created.
+\end{command}
+
+\begin{command}{\pgfplotstablegetelem\marg{row}\marg{col}\textbackslash of\meta{table}}
+ Selects a single table element at row \marg{row} and column \marg{col}. The second argument has the same format as that described in the last paragraph: it should be a column name or a column index (in which case it needs to be written as |[index]|\meta{number}).
+
+ The return value will be written to |\pgfplotsretval|.
+\begin{codeexample}[]
+\pgfplotstableread{pgfplotstable.example1.dat}{\table}
+\pgfplotstablegetelem{4}{error1}\of{\table}
+The value (4,error1) is `\pgfplotsretval'.
+
+\pgfplotstablegetelem{2}{[index]0}\of{\table}
+The value (2,0) is `\pgfplotsretval'.
+\end{codeexample}
+
+ \paragraph{Attention:} If possible, avoid using this command inside of loops. It is quite slow.
+\end{command}
+
+\begin{command}{\pgfplotstablegetrowsof\marg{file name or \textbackslash loadedtable}}
+ Defines |\pgfmathresult| to be the number of rows in a table. The argument may be either a file name or an already loaded table (the \meta{\textbackslash macro} of |\pgfplotstableread|).
+\end{command}
+
+
+\begin{command}{\pgfplotstablevertcat\marg{\textbackslash table1}\marg{\textbackslash table2 or filename}}
+ See page \pageref{table:vertcat} for details about this command.
+\end{command}
+
+\begin{command}{\pgfplotstablenew\oarg{options}\marg{row count}\marg{\textbackslash table}}
+ See section~\ref{pgfplotstable:createcol} for details about this command.
+\end{command}
+\begin{command}{\pgfplotstablecreatecol\oarg{options}\marg{row count}\marg{\textbackslash table}}
+ See section~\ref{pgfplotstable:createcol} for details about this command.
+\end{command}
+
+\begin{commandlist}{%
+ \pgfplotstabletranspose\oarg{options}\marg{\textbackslash outtable}\marg{\textbackslash table or filename},%
+ \pgfplotstabletranspose*\oarg{options}\marg{\textbackslash outtable}\marg{\textbackslash table or filename}}%
+ Defines \meta{\textbackslash outtable} to be the transposed of \marg{\textbackslash table of filename}. The input argument can be either a file name or an already loaded table.
+
+ The version with `|*|' is only interesting in conjunction with the |columns| option, see below.
+
+\begin{codeexample}[]
+\pgfplotstabletypeset[string type]{pgfplotstable.example3.dat}
+\end{codeexample}
+
+\begin{codeexample}[]
+\pgfplotstabletranspose\table{pgfplotstable.example3.dat}
+\pgfplotstabletypeset[string type]\table
+\end{codeexample}
+
+ The optional argument \meta{options} can contain options which influence the transposition:
+ \begin{pgfplotskey}{table/colnames from=\marg{colname} (initially empty)}
+ Inside of |\pgfplotstabletranspose|, this key handles how to define output column names.
+
+ If \marg{colname} \emph{is} empty (the initial value), the output column names will simply be the old row indices, starting with~$0$.
+
+ If \marg{colname} is not empty, it denotes an input column name whose cell values will make up the output column names:
+\begin{codeexample}[]
+\pgfplotstabletranspose[colnames from=c]\table{pgfplotstable.example3.dat}
+\pgfplotstabletypeset[string type]\table
+\end{codeexample}
+ The argument \meta{colname} won't appear as cell contents. It is an error if the the cells in \meta{colname} don't yield unique column names.
+ \end{pgfplotskey}
+
+ \begin{pgfplotskey}{table/input colnames to=\marg{name} (initially colnames)}
+ Inside of |\pgfplotstabletranspose|, this key handles what to do with \emph{input} column names.
+
+ Will create a further column named \meta{name} which will be filled with the input column names (as string type).
+\begin{codeexample}[]
+\pgfplotstabletranspose[input colnames to=Input]\table{pgfplotstable.example3.dat}
+\pgfplotstabletypeset[string type]\table
+\end{codeexample}
+ Set \meta{name} to the empty string to disable this column.
+\begin{codeexample}[]
+\pgfplotstabletranspose[input colnames to=]\table{pgfplotstable.example3.dat}
+\pgfplotstabletypeset[string type]\table
+\end{codeexample}
+ \end{pgfplotskey}
+
+ \begin{pgfplotskey}{table/columns=\marg{list} (initially empty)}
+ Inside of |\pgfplotstabletranspose|, this key handles which input columns shall be considered for the transposition.
+
+ If \meta{list} is empty, all columns of the input table will be used (which is the initial configuration).
+
+ If \meta{list} is not empty, it is expected to be a list of column names. Only these columns will be used as input for the transposition, just as if the remaining one weren't there. It is acceptable to provide column aliases or |create on use| arguments inside of \meta{list}.
+\begin{codeexample}[]
+\pgfplotstabletranspose[columns={a,b}]\table{pgfplotstable.example3.dat}
+\pgfplotstabletypeset[string type]\table
+\end{codeexample}
+
+ Here is the only difference between |\pgfplotstabletranspose| and |\pgfplotstabletranspose*|: the version without `|*|' \emph{resets} the |columns| key before it starts whereas the version with `|*|' simply uses the actual content of |columns|.
+ \end{pgfplotskey}
+\end{commandlist}
+
+\subsection{Repeating Things: Loops}
+\begin{command}{\foreach \meta{variables} |in| \meta{list} \marg{commands}}
+ A powerful loop command provided by \Tikz, see~\cite[Section Utilities]{tikz}.
+\begin{codeexample}[]
+\foreach \x in {1,2,...,4} {Iterating \x. }%
+\end{codeexample}
+
+ A \PGFPlots\ related example could be
+\begin{codeexample}[code only]
+\foreach \i in {1,2,...,10} {\addplot table {datafile\i}; }%
+\end{codeexample}
+\end{command}
+
+\noindent The following loop commands come with \PGFPlots. They are similar to the powerful \Tikz\ |\foreach| loop command, which, however, is not always useful for table processing: the effect of its loop body end after each iteration.
+
+The following \PGFPlots\ looping macros are an alternative.
+
+\begin{command}{\pgfplotsforeachungrouped \meta{variable} |in| \meta{list} \marg{command}}
+ A specialised variant of |\foreach| which can do two things: it does not introduce extra groups while executing \meta{command} and it allows to invoke the math parser for (simple!) \meta{$x_0$}|,|\meta{$x_1$}|,...,|\meta{$x_n$} expressions.
+
+\begin{codeexample}[]
+\def\allcollected{}
+\pgfplotsforeachungrouped \x in {1,2,...,4} {Iterating \x. \edef\allcollected{\allcollected, \x}}%
+All collected = \allcollected.
+\end{codeexample}
+
+ A more useful example might be to work with tables:
+
+\begin{codeexample}[code only]
+\pgfplotsforeachungrouped \i in {1,2,...,10} {%
+ \pgfplotstablevertcat{\output}{datafile\i} % appends `datafile\i' -> `\output'
+}%
+% since it was ungrouped, \output is still defined (would not work
+% with \foreach)
+\end{codeexample}
+
+ \paragraph{Remark: } The special syntax \meta{list}=\meta{$x_0$}|,|\meta{$x_1$}|,...,|\meta{$x_n$}, i.e.\ with two leading elements, followed by dots and a final element, invokes the math parser for the loop. Thus, it allows larger number ranges than any other syntax if |/pgf/fpu| is active. In all other cases, |\pgfplotsforeachungrouped| invokes |\foreach| and provides the results without \TeX\ groups.
+
+\end{command}
+
+\begin{command}{\pgfplotsinvokeforeach\marg{list} \marg{command}}
+ A variant of |\pgfplotsforeachungrouped| (and such also of |\foreach|) which replaces any occurence of |#1| inside of \meta{command} once for every element in \meta{list}. Thus, it actually assumes that \marg{command} is like a |\newcommand| body.
+
+ In other words, \marg{command} is invoked for every element of \marg{list}. The actual element of \marg{list} is available as |#1|.
+
+ As |\pgfplotsforeachungrouped|, this command does \emph{not} introduce extra scopes (i.e.\ it is ungrouped as well).
+
+ The difference to |\foreach \x in |\meta{list}\marg{command} is subtle: the |\x| would \emph{not} be expanded wheres |#1| is.
+\begin{codeexample}[]
+\pgfkeys{
+ otherstyle a/.code={[a]},
+ otherstyle b/.code={[b]},
+ otherstyle c/.code={[c]},
+ otherstyle d/.code={[d]}}
+\pgfplotsinvokeforeach{a,b,c,d}
+ {\pgfkeys{key #1/.style={otherstyle #1}}}
+Invoke them: \pgfkeys{key a} \pgfkeys{key b} \pgfkeys{key c} \pgfkeys{key d}
+\end{codeexample}
+The counter example would use a macro (here |\x|) as loop argument:
+\begin{codeexample}[]
+\pgfkeys{
+ otherstyle a/.code={[a]},
+ otherstyle b/.code={[b]},
+ otherstyle c/.code={[c]},
+ otherstyle d/.code={[d]}}
+\pgfplotsforeachungrouped \x in {a,b,c,d}
+ {\pgfkeys{key \x/.style={otherstyle \x}}}
+Invoke them: \pgfkeys{key a} \pgfkeys{key b} \pgfkeys{key c} \pgfkeys{key d}
+\end{codeexample}
+
+ \paragraph{Restrictions:} you can't nest this command yet (since it does not introduce protection by scopes).
+\end{command}
\printindex
\bibliographystyle{abbrv} %gerapali} %gerabbrv} %gerunsrt.bst} %gerabbrv}% gerplain}