14.10.2014 Views

gnuplot documentation

gnuplot documentation

gnuplot documentation

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

60 PLOT <strong>gnuplot</strong> 4.3 75<br />

In this example the data are read from the file "MyData" using a more complicated format:<br />

plot ’MyData’ using "%*lf%lf%*20[^\n]%lf"<br />

The meaning of this format is:<br />

%*lf<br />

%lf<br />

%*20[^\n]<br />

%lf<br />

ignore a number<br />

read a double-precision number (x by default)<br />

ignore 20 non-newline characters<br />

read a double-precision number (y by default)<br />

One trick is to use the ternary ?: operator to filter data:<br />

plot ’file’ using 1:($3>10 ? $2 : 1/0)<br />

which plots the datum in column two against that in column one provided the datum in column three<br />

exceeds ten. 1/0 is undefined; <strong>gnuplot</strong> quietly ignores undefined points, so unsuitable points are<br />

suppressed.<br />

In fact, you can use a constant expression for the column number, provided it doesn’t start with an<br />

opening parenthesis; constructs like using 0+(complicated expression) can be used. The crucial<br />

point is that the expression is evaluated once if it doesn’t start with a left parenthesis, or once for each<br />

data point read if it does.<br />

If timeseries data are being used, the time can span multiple columns. The starting column should be<br />

specified. Note that the spaces within the time must be included when calculating starting columns for<br />

other data. E.g., if the first element on a line is a time with an embedded space, the y value should be<br />

specified as column three.<br />

It should be noted that plot ’file’, plot ’file’ using 1:2, and plot ’file’ using ($1):($2) can be subtly<br />

different: 1) if file has some lines with one column and some with two, the first will invent x values<br />

when they are missing, the second will quietly ignore the lines with one column, and the third will store<br />

an undefined value for lines with one point (so that in a plot with lines, no line joins points across the<br />

bad point); 2) if a line contains text at the first column, the first will abort the plot on an error, but the<br />

second and third should quietly skip the garbage.<br />

In fact, it is often possible to plot a file with lots of lines of garbage at the top simply by specifying<br />

plot ’file’ using 1:2<br />

However, if you want to leave text in your data files, it is safer to put the comment character (#) in the<br />

first column of the text lines.<br />

Feeble using demos.<br />

If <strong>gnuplot</strong> is built with configuration option –enable-datastrings, then additional modifiers to using can<br />

specify handling of text fields in the datafile. See datastrings (p. 24), using xticlabels (p. 75),<br />

using title (p. 75).<br />

60.2.9.1 Using title If <strong>gnuplot</strong> is built with configuration option –enable-datastrings, then the first<br />

entry of a column of the input data file can be used as a string to provide the plot title in the key box.<br />

The column containing specified is independent of the column[s] used for the plot itself.<br />

plot ’data’ using 1:($2/$3) title column(N)<br />

In this case the entry in the first row of column N will be used for the key entry of the plot constructed<br />

from dividing column 2 by column 3. The entry in the first row of columns 2 and 3 will be ignored.<br />

60.2.9.2 Xticlabels If <strong>gnuplot</strong> is built with configuration option –enable-datastrings, then a column<br />

of the input data file can be used to label axis tic marks. The format of such a plot command is<br />

plot ’datafile’ using ::xticlabels() with

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!