Plotting Data
With a file name as an argument, instead of a function, plot
draws a graph with the first columnn of the file along the x-axis and
the second column along y. The file name must appear in single or
double quotes. For example,
plot "my-data-file"
will pop open a window on your display, draw a box with numbered axes,
and draw a labeled graph.
- Note: If "my-data-file" is
"-", the data are read from standard input. If instead we
use "<program", gnuplot runs the program and reads the
data from its output stream. This is a very powerful way of writing
"subroutines" for gnuplot.
A more complete plot command might look like
plot [x-range] [y-range] \
"my-data-file" \
every sampling-interval \
using column-list \
with points-or-lines
The backslash ("\") at the end of some of the above lines is a
continuation character, meaning that the command extends onto the next
line. The other pieces have the following meanings.
- [x-range]
- Optionally specify the ranges to use for the x- and y-axes. The
format is [low:high]. Similarly for [y-range].
The default is for gnuplot to determine the range automatically.
- every sampling-interval
- Specify which points (i.e. lines in the datafile) to plot. By
default, every point is displayed. A sampling interval of 2 means
every other point, and so on.
- using column-list
- Specify which columns to plot, in the form xcol:ycol.
The default is 1:2.
- with points-or-lines
- Specify whether to plot isolated points, or connect them by
lines. The default is points.
Commands may be ruthlessly abbreviated, and several graphs may be
drawn by specifying more file names, row and column ranges, and point
styles, separated by commas. Note that the order of the various
options is significant, and must be maintained.
EXAMPLE 1:
plot [0:10] [-1:1] "data1" us 1:2 w lines, \
"data1" ev 2 usi 1:3 with points, \
"data3" ev 3 using 3:2 wi points
will plot three graphs on the same axes, one with lines, two with
points, using data from two data files, showing every point in the
first graph, every other one in the second, and every sixth in the
third.
EXAMPLE 2:
plot "data2" with points
will plot a collection of 1000 points randomly distributed in the unit
square.
Numerous line and point styles are available, as described here.