5. CSV and expressions
Many tools write CSV with a header row, run.csv too:
text
$ head -n 3 run.csv
iteration,continuity,momentum,energy,cd,dcd
1, 1.00482E+00, 4.51026E-01, 1.77828E+00, 5.36869E-01, 4.00000E-02
2, 9.88751E-01, 4.03780E-01, 1.58489E+00, 5.18076E-01, 2.82843E-02Tell foresight the separator, and the header names the columns:
gnuplot
set datafile separator comma
set key autotitle columnheadgnuplot
plot 'run.csv' using "iteration":(column("cd") * 1e4), \
'' using 1:($1 > 60 ? $5 * 1e4 : 1/0) with points pt 6 title 'after the restart'set datafile separator comma(ortab, or any characters";,"): every separator ends a cell; an empty cell is a gap.unset datafilegoes back to whitespace.- A quoted name selects a column by its header:
using "iteration":..., andcolumn("cd")inside an expression. set key autotitle columnheadtitles each item with the header of its y column; an explicittitlestill wins. Once headers are in use, the first row of each dataset is a header, not a point.- A parenthesized field is an expression evaluated on each row:
$5andcolumn(5)are column 5,$0the point number; gnuplot's operators and functions, its integer division included. 1/0is undefined:($1 > 60 ? $5 * 1e4 : 1/0)keeps the points after the restart and drops the others.
What you learned
CSV, columns by name, titles from the header, computed columns and filters. Reference: Data Files, gnuplot Subset, expressions.
Next: 6. Two axes and a model.