Credits | Overview | Plotting Styles | Commands | Terminals |
---|
This creates a plot of the sum of the 2nd and 3rd data against the first: The format string specifies comma- rather than space-separated columns. The same result could be achieved by specifying set datafile separator comma.
plot 'file' using 1:($2+$3) '%lf,%lf,%lf'
In this example the data are read from the file "MyData" using a more complicated format:
plot 'MyData' using "%*lf%lf%*20[^\n]%lf"
The meaning of this format is:
%*lf ignore a number %lf read a double-precision number (x by default) %*20[^\n] ignore 20 non-newline characters %lf read a double-precision number (y by default)
One trick is to use the ternary ?: operator to filter data:
plot 'file' using 1:($3>10 ? $2 : 1/0)
which plots the datum in column two against that in column one provided the datum in column three exceeds ten. 1/0 is undefined; gnuplot quietly ignores undefined points, so unsuitable points are suppressed. Or you can use the pre-defined variable NaN to achieve the same result.
In fact, you can use a constant expression for the column number, provided it doesn't start with an opening parenthesis; constructs like using 0+(complicated expression) can be used. The crucial point is that the expression is evaluated once if it doesn't start with a left parenthesis, or once for each data point read if it does.
If timeseries data are being used, the time can span multiple columns. The starting column should be specified. Note that the spaces within the time must be included when calculating starting columns for other data. E.g., if the first element on a line is a time with an embedded space, the y value should be specified as column three.
It should be noted that (a) plot 'file', (b) plot 'file' using 1:2, and (c) plot 'file' using ($1):($2) can be subtly different. See missing.
It is often possible to plot a file with lots of lines of garbage at the top simply by specifying
plot 'file' using 1:2
However, if you want to leave text in your data files, it is safer to put the comment character (#) in the first column of the text lines.