Syntax:
plot 'file' using { spec:spec:... } {'format'}
If a format is specified, each datafile line is read using the c library's scanf function, with the specified format string. Otherwise the line is read and broken into columns at spaces or tabs. A format cannot be specified if time-format data is being used (see set data time).
The resulting array of data is then sorted into columns according to the specs. Each spec is either a simple column number, which selects the datum, or an expression enclosed in round brackets (parentheses). The expression can use $1 to access the first item read, $2 for the second item, and so on. It can also use column(x) and valid(x) where x is an arbitrary expression resulting in an integer. column(x) returns the x'th datum; valid(x) tests that datum x is a valid number. A column number of 0 generates a number increasing (from zero) with each point, reset at double blank lines.
plot 'file' using 1 is identical to plot 'file' using 0:1.
N.B.—the call command also uses $'s as a special character.
The interpretation of the columns depends on the plot and style. For splot, a single column is z, or three columns are (x,y,z) (unless set mapping has been used). For plot, a single column is y. For plot or fit, the first two columns are x and y; additional columns are usually errors in x and/or y. See set style for more details about the structure of files containing error information.
Examples:
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.)
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 the first number %lf read in the second and assign to x %*20[^\n] ignore 20 non-newline characters %lf read in the y value
Note that the use of newline ( \n) requires use of double-quotes rather than single-quotes.
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.
In fact, you can use a constant expression for the column number, provided it doesn't start with an opening bracket. Something 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 bracket, or once for each data point read if it does start with a bracket.
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 plot 'file', plot 'file' using 1:2, and plot 'file' using ($1):($2) can be subtly different: 1) if file has some lines with one column and some with two, the first will invent x values when they are missing, the second will quietly ignore the lines with one column, and the third will store an undefined value for lines with one point (so that in a plot with lines, no line joins points across the bad point); 2) if a line contains text at the first column, the first will abort the plot on an error, but the second and third should quietly skip the garbage.
In fact, 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
If you want to leave text in your data files, it is always safe to put the comment character (#) in the first column of the text lines.