Appendix B. Creating Graphs with Gnuplot
Gnuplot is an open source program for plotting data and functions. It is intended primarily for Unix/Linux systems, although versions for Windows and the Mac exist as well.
Basic Plotting
When started, gnuplot provides a shell-like interactive command prompt. All plotting is done using the plot command, which has a simple syntax. To plot a function, you would type (at the gnuplot prompt):
plot sin(x)
By default, gnuplot assumes that data is stored in white-space separated text files, with
one line per data point. To plot data from a file (residing in the current directory and named
data), you would use the following:
plot "data" using 1:2 with lines
This assumes that the values used for the horizontal position (the x values) are in the first column, and the values for the vertical position (the y values) are in the second column. Of course, any column can be used for either x or y values.
Gnuplot makes it easy to combine multiple curves on one plot. Assume that the data file looks like the one shown in Figure B-1 (left). Then the following command would plot the values of both the second and the third column, together with a function, in a single graph (Figure B-1, right):
plot "data" u 1:2 w lp, "data" u 1:3 w lp, 5*exp(-5*x)
Here we have made use of the fact that many directives can be abbreviated (u for using and w for with) and have also
introduced a new plotting style, linespoints (abbreviated
lp), which plots values as symbols connected by lines. ...