|
Ploticus can read tabular ASCII data from files, commands, or from standard input.
If you're using prefabs, your data source is specified on the command line eg. data=myfile.dat.
If you're writing scripts,
proc getdata
is used to read data.. data can also be embedded directly into scripts.
See alsoproc getdataPlotting from data fieldsPlotting and data display operations are done using fields. Suppose we have a data set like this in the file myfile.dat: F1 2.43 0.47 PF7955 F2 2.79 0.28 PT2705 F3 2.62 0.37 PB2702Suppose we want to draw a bar graph using the values in field 2, and draw error bars using the values in field 3. Fields can be specified by number, so we could use this command: pl -prefab vbars data=myfile.dat y=2 err=3If your data set has a field name header (field names in the first row) you can reference fields using those names if you want to. For example: test level se case_id F1 2.43 0.47 PF7955 F2 2.79 0.28 PT2705 F3 2.62 0.37 PB2702..we could use this command: pl -prefab vbars data=myfile.dat header=yes y=level err=seThe field name header must use the same delimitation as the data proper. Field names are like variable names; they cannot contain embedded white space, comma, or quote characters. Script writers can use field names by setting the fieldnameheader option to yes. Script writers can also assign field names explicitly if desired. Recognized data formatsData files or streams should be plain ASCII text, not binary, and should be organized as a collection of rows having one or more fields. Fields may have numeric or alphanumeric content and may be delimited in one of these ways:
Notes regarding data input and parsingNumeric values in scientific notation - as of 2.30 these should be handled transparently. Empty rows and commented rows are ignored. The default comment symbol is // and it should appear before any other content on a line. An alternate comment symbol can be specified if desired. Number of data fields per row (record): Proc getdata needs to get a fixed idea of the number of data fields per row to be parsed and stored. In most cases the number of fields is uniform on all rows, so this isn't an issue. But where the number of fields differs between rows, or where the number of field names disagrees with the number of data fields, here is the behavior: Number of expected fields can be explicitly specified by setting nfields. Or, if data field names exist, the expected number of data fields will be the same as the number of field names. Otherwise, the first usable data row will dictate the expected number of data fields per row. If a certain data row has more than the expected number of fields, extra fields are silently ignored. If a row has less than the expected number of fields, blank fields are silently added until the record has same number of fields as other records. Rows may be conditionally selected at the time of reading by specifying a select condition. Rows not meeting the condition will be skipped. Leading white space is allowed when using whitespace or spacequoted delimitation. It is not allowed on the other types. Comments / empty lines in comma-delimited data files: Comment symbol must be at beginning of line, and empty lines may not contain any whitespace. Row termination: Each row, including the last one, should be terminated with a newline or CR/LF.
When specifying data within the ploticus script:
Data are subject to side-effects of script interpreter, including leading white space
stripped off and constructs that resemble script operators or variables may be evaluated/expanded.
Missing dataMissing data values may be represented using a code or by a zero-length field, depending on the delimitation method. A value is considered missing if it is non-plottable.. ie if plotting numerics any non-numeric value is considered missing data; if plotting dates any value that isn't a date (in the current format) is considered missing data. When plotting, missing values are generally skipped over, but exactly what occurs depends on what kind of plot operation is being done.Embedded #set statementsData files may contain embedded #set statements for setting prefab parameters and ploticus variables directly from the data file. The syntax is:
The #set statements should be given before the first row of data in the file. All tokens are separated by whitespace and quoting is never used. Here's an example of a data file with embedded #set statements:
Some prefab parameters (those that control data input or that are accessed by the prefab
before the data are read) cannot be #set within the data file, or will be problematic when
set this way. If a prefab parameter doesn't seem to be working correctly when set from within
a data file, try setting it on the command line instead. Another way to determine this is to
run the prefab with -echo and check the script output to see if the parameter is accessed before the
proc getdata.
Other possibilitiesSince ploticus can read data on standard input, there are many possibilities for getting data for plotting. To get data out of an SQL database, use your database's command line tool to extract tabular ASCII data. Or, to get data across the internet using a URL, use a utility like Jeff Poskanzer's http_get. Be sure to set delim appropriately. These examples illustrate:
If you are developing ploticus scripts, and your data exists in a state such that additional processing is required in order to work with it, you may be able to accomplish the desired manipulation within ploticus. To select certain fields, reformat fields, concatenate fields, etc., try using a proc getdata filter. To perform accumulation, tabulation and counting, rewriting as percents, computation of totals, reversing record order, rotation of row/column matrix, break processing, etc., proc processdata may be useful (it operates on the data after they have been read in).
Script writers wishing to embed large amounts of data directly into a script
may be interested in
proc trailer,
which allows the data to be given
at the end of the script file, to get it out of the way.
The current data setWithin a script, proc getdata can be invoked any number of times to read in data. However there can only be one active data set at any one time. This is referred to as the "current data set".Note that proc getdata isn't the only way that the current data set can be filled. Proc processdata and proc tabulate perform computations using the current data set, and then produce a new data set as a result.. and the result then becomes the current data set.
It is possible for the original data set to remain in memory when
proc processdata
produces new results--
in fact if proc processdata is invoked several times there can be several data sets "stacked"
in memory (this is an effective technique when plotting a series of derivations).
By default the most recently created data set is the "current" one.
Proc usedata
can be used to select an earlier data set to be the current one.
If a new data set is read by
proc getdata
this entire stack structure is cleared.
Data sets cannot be stacked by proc getdata.
ExamplesHere are some script examples:scat7.dat (white-space delimited) stock.csv (comma delimited) timeline3 (data specified within script) km2 (data specified within script). |
![]() data display engine Copyright Steve Grubb ![]() |