Very Basic GNUPLOT
Chuck Gartland
September 2001


GNUPLOT is an easy-to-use interactive plotting package installed on the Math/CS computer network. It is entered with the command
% gnuplot
``%'' is the UNIX command prompt. Exit with either of the commands
gnuplot> exit     or     quit
``gnuplot>'' is the GNUPLOT command prompt. GNUPLOT is a public-domain package, available via anonymous ftp from in the subdirectory /pub/gnuplot. There is a brief man page
% man gnuplot
and an extensive on-line help facility available inside the program:
gnuplot> ?     or     help     or     help topic
First time users should peruse the man page and should read
gnuplot> help plotting
GNUPLOT draws pictures of two- and three-dimensional functions and data in windows on your workstation screen. It can also write to disk PostScript-language plot files, which can be printed on the laser printers. This very brief introduction discusses (through a few sample commands) how to use GNUPLOT to plot functions and to do simple ``connect the dots'' plotting of data from a disk file. It also discusses how to print out hard copy of output on a laser printer.

Plotting Functions

gnuplot> plot sin(x)
will plot the function sin(x), on the default domain [-10,10].  To specify a different domain, one can use (for example)
gnuplot> plot [x=0:2*pi] sin(x)

Connecting the Dots

gnuplot> plot "plot.dat" with lines
will draw a simple 2-D plot, connecting the dots with straight lines, of the data in the local file ``plot.dat''. This file must have been generated previously (usually as the output from some other user program) and in the current working directory (or prescribed with its full path name). The contents of this ascii file should be two numbers (separated by spaces) per line--any number of lines--representing the (x,y) coordinates of the data points to be plotted.
gnuplot> plot "plot1.dat" with lines, "plot2.dat" with points
will plot both ``plot1.dat'' and ``plot2.dat'' on the same plot, using lines for the first data set and points for the second. The same effect can be accomplished with the following two commands in succession:
gnuplot> plot "plot1.dat" with lines
gnuplot> replot "plot2.dat" with points
For more information on these basic and important plotting commands:
gnuplot> help plot     and     help replot

Hard Copy Output

Once you have your plots looking as you wish in your viewing window, the following sequence of commands can be used to generate a PostScript-language disk file (here called ``'') for laser printing hard-copy output:
gnuplot> set terminal postscript
gnuplot> set output ""
gnuplot> replot     or     original plotting command(s)
The generated disk file can be laser printed (on your default printer) with the command (outside of GNUPLOT, at the UNIX level)
% lp   (HP-UX)     or     % lpr   (Linux)
or on the selected printer graphlab (for example), via
% lp -dgraphlab     or     % lpr -Pgraphlab
For further GNUPLOT ``window plotting,'' you must reset these variables to their defaults by using the commands
gnuplot> set terminal x11
gnuplot> set output "STDOUT"     or     set output
For more information on this other basic command, and to see what other kinds of things can be ``set'':
gnuplot> help set
Chuck Gartland  /
September, 2001