The following classes provide data for the plot() method of a graph. The classes are implemented in graph.data.
| filename, commentpattern=defaultcommentpattern, columnpattern=defaultcolumnpattern, stringpattern=defaultstringpattern, skiphead=0, skiptail=0, every=1, title=notitle, context={}, copy=1, replacedollar=1, columncallback="__column__", **columns) |
The arguments commentpattern, columnpattern, and stringpattern are responsible for identifying the data in each line of the file. Lines matching commentpattern are ignored except for the column name search of the last non-empty comment line before the data. By default a line starting with one of the characters "#", "%", or "!" as well as an empty line is treated as a comment.
A non-comment line is analysed by repeatedly matching stringpattern and, whenever the stringpattern does not match, by columnpattern. When the stringpattern matches, the result is taken as the value for the next column without further transformations. When columnpattern matches, it is tried to convert the result to a float. When this fails the result is taken as a string as well. By default, you can write strings with spaces surrounded by """ immediately surrounded by spaces or begin/end of line in the data file. Otherwise """ is not taken to be special.
skiphead and skiptail are numbers of data lines to be ignored at the beginning and end of the file while every selects only every every line from the data.
title is the title of the data to be used in the graph key. A
default title is constructed out of filename and
**columns. You may set title to None to disable
the title.
Finally, columns define columns out of the existing columns from the file by a column number or a mathematical expression (see below). When copy is set the names of the columns in the file (file column names) and the freshly created columns having the names of the dictionary key (data column names) are passed as data to the graph styles. The data columns may hide file columns when names are equal. For unset copy the file columns are not available to the graph styles.
File column names occur when the data file contains a comment line immediately in front of the data (except for empty or empty comment lines). This line will be parsed skipping the matched comment identifier as if the line would be regular data, but it will not be converted to floats even if it would be possible to convert the items. The result is taken as file column names, i.e. a string representation for the columns in the file.
The values of **columns can refer to column numbers in the
file starting at 1. The column 0 is also available
and contains the line number starting from 1 not counting
comment lines, but lines skipped by skiphead, skiptail,
and every. Furthermore values of **columns can be
strings: file column names or complex mathematical expressions. To
refer to columns within mathematical expressions you can also use
file column names when they are valid variable identifiers. Equal
named items in context will then be hidden. Alternatively columns
can be access by the syntax $<number>
when replacedollar is set. They will be translated into
function calls to columncallback, which is a function to
access column data by index or name.
context allows for accessing external variables and functions when evaluating mathematical expressions for columns. Additionally to the identifiers in context, the file column names, the columncallback function and the functions shown in the table ``builtins in math expressions'' at the end of the section are available.
Example:
graph.data.file("test.dat", a=1, b="B", c="2*B+$3")
# A B C 1.234 1 2 5.678 3 4
"a", "b", "c" will become
"[1.234, 5.678]", "[1.0, 3.0]", and "[4.0,
10.0]", respectively. The columns "A", "B",
"C" will be available as well, since copy is enabled by
default.
When creating several data instances accessing the same file, the file is read only once. There is an inherent caching of the file contents.
For the sake of completeness we list the default patterns:
re.compile(r"(#+|!+|%+)\s*")
re.compile(r"\"(.*?)\"(\s+|$)")
re.compile(r"(.*?)(\s+|$)")
| expression, title=notitle, min=None, max=None, points=100, context={}) |
"y(x)=sin(x)".
title is the title of the data to be used in the graph key. By
default expression is used. You may set title to
None to disable the title.
min and max give the range of the variable. If not set, the range spans the whole axis range. The axis range might be set explicitly or implicitly by ranges of other data. points is the number of points for which the function is calculated. The points are choosen linearly in terms of graph coordinates.
context allows for accessing external variables and functions. Additionally to the identifiers in context, the variable name and the functions shown in the table ``builtins in math expressions'' at the end of the section are available.
| varname, min, max, expression, title=notitle, points=100, context={}) |
expression is the mathematical expression for the parametric
function. It contains an assignment of a tuple of functions to a
tuple of variables. A typical example looks like
"x, y = cos(k), sin(k)".
title is the title of the data to be used in the graph key. By
default expression is used. You may set title to
None to disable the title.
context allows for accessing external variables and functions. Additionally to the identifiers in context, varname and the functions shown in the table ``builtins in math expressions'' at the end of the section are available.
| title="user provided values", **columns) |
title is the title of the data to be used in the graph key.
| data, title="user provided points", addlinenumbers=1, **columns) |
title is the title of the data to be used in the graph key.
The keywords of **columns become the data column names. The values are the column numbers starting from one, when addlinenumbers is turned on (the zeroth column is added to contain a line number in that case), while the column numbers starts from zero, when addlinenumbers is switched off.
| data, title=notitle, context=, copy=1, replacedollar=1, columncallback="__column__", **columns) |
| filename, title=notitle, context=, copy=1, replacedollar=1, columncallback="__column__", **columns) |
Each section of the config file becomes a data line. The options in a section are the columns. The name of the options will be used as file column names. All other parameters work as in graph.data.file and graph.data.data since they all use the same code.
| filename, minrank=None, maxrank=None, title=notitle, context=, copy=1, replacedollar=1, columncallback="__column__", **columns) |
The builtins in math expressions are listed in the following table:
| name | value |
|---|
math refers to Pythons math module. The
splitatvalue function is defined as:
| value, *splitpoints) |
(section, value).
The section is calculated by comparing value with the values
of splitpoints. If splitpoints contains only a single item,
section is 0 when value is lower or equal this item
and 1 else. For multiple splitpoints, section is
0 when its lower or equal the first item, None when
its bigger than the first item but lower or equal the second item,
1 when its even bigger the second item, but lower or equal
the third item. It continues to alter between None and
2, 3, etc.