Gnuplot is installed and available for both IRIX and HP/UX machines, so it can be used from any SGI or HP in MacLean. Invoke it by simply typing
gnuplot
Gnuplot is available on silicon. To use it, you must set up the remote display of X Windows System programs as detailed in the 22C:132 Parallel Programming FAQ. Then, start it as above.
In case you're interested, Gnuplot is available for Windows, Macintosh, Linux, etc. It may be down-loaded and installed for free. The official distribution is archived at
ftp://ftp.dartmouth.edu/pub/gnuplot/plus several mirror sites. See below for more information on acquiring Gnuplot for yourself.
Gnuplot is interactive and command-line based. The prompt looks like
gnuplot>Command line editing and history behaves very much like most shells: the left and right arrow keys allow you to edit commands and the up and down arrow keys cycle through the command history.
There is very extensive online help available at all times. From the gnuplot> prompt, simply type
helpThe online help goes into far greater detail than this FAQ does.
The most important command is plot. This command will graph several 2-dimensional graphs over the range and domain you specify. For example:
plot [-pi:pi] [-1:1] sin(x)This command will plot the sin function over the domain (-pi, pi) and the range (-1, 1). To plot more than one function over the same domain and range, just separate them with commas:
plot [-pi:pi] [-1:1] sin(x), cos(x)As you can see, Gnuplot recognizes x as the independent variable.
Expressions are specified using C language syntax. All C operators and most math functions are available.
Another handy command is splot which will plot a surface in 3 dimensions. For example:
splot [-1:1] [-1:1] [0:2] x*x + y*yGnuplot recognizes x and y as the independent variables and it allows you to specify a third range for z.
These commands have many many options, all of which are explained by the online help:
help plotor
help splot
Gnuplot has a number of internal variables with which you may specify the behavior of the plotter and the appearance of the plots. For example, the variable title contains any title which may appear at the top of a plot. You can determine the current setting of a variable at the Gnuplot command line with the show command:
show titleYou can change a variable's value with the set command:
set title "United States National Debt"Some variables are toggles. For example, the variable hidden3d indicates whether hidden surface removal should be applied to a 3D plot. You can still determine the current setting of a toggle variable with the show command:
show hidden3dYou can also still set a variable's value with the set command:
set hidden3dBut you reset it with another set command:
set nohidden3dA list of all internal variables can be found with the command
help setand a description of a specific variable, for example hidden3d can be found with the command
help set hidden3d
Commands do not need to be typed manually each time. If there is a set of commands which you repeatedly use, or if the command you want to execute is simply really long (Gnuplot does not handle long command lines well at all) you may use your favorite editor to put it into a file. You can then run all commands in a file, for example myplots.gnu like this:
load "myplots.gnu"Each command in the file will be executed as if you'd typed it at the Gnuplot prompt. Within this file, all lines beginning with # are taken to be comments and are ignored.
Gnuplot would hardly be useful to us if it couldn't be used to plot generated data. One may plot data by specifying the name of a data file instead of the name of a function. Input files may be in one of several formats.
The simplest file has one value per line. The domain of the data is taken to be (0, n-1) where n is the number of data points. Take this example file: data1
1.00000 1.50000 2.00000 2.50000 3.00000This data may be plotted with the command:
plot "data1"Gnuplot will treat this input as the list of points (0, 1), (1, 1.5), (2, 2), (3, 2.5), (4, 3.0). It will determine the domain and range of the data and plot it accordingly. By default, the data will be plotted as points. To connect the points with lines:
plot "data1" with lines
You may also specify data with two values per line. Here is data2:
1.00000 1.00000 2.00000 1.50000 4.00000 2.00000 8.00000 2.50000 16.00000 3.00000This data may be plotted with the same command. Gnuplot will assume (x, y) pairs.
One of the great features of Gnuplot is its ability to accept input data from a pipe. If your program outputs data in one of the above formats, it may be piped directly into Gnuplot without the need of an intermediate data file. For example, if your program's name is myprog, you may plot its output directly with the command
plot "< myprog"
The terminal variable determines where output is sent. By default, the value of terminal is x11. This is fine if you're using an X terminal and you want to see your graph in a window. However, it's quite likely you'll want to produce hard-copy output sometime. The easiest way is to use PostScript. To do this, change the value of terminal like this:
set terminal postscriptNow, when you execute the plot command, the on-screen window will not appear, and instead a PostScript file will be created.
Generating color PostScript it is equally easy.
set terminal postscript colorRemember to change terminal back to x11 after generating your output files, in order to see your output interactively again.
By default your output will be sent to stdout. This may be changed by setting the output variable. To produce a file named data.ps:
set output "data.ps"and then replot your graph. To reset output back to stdout, specify nothing:
set outputIt doesn't matter if output is set when terminal is x11 since there is no file output in that case anyway.
Generated PostScript files may be sent to any PostScript capable printer (that's about all of them) with the lp command. To print the file data.ps to the HP LaserJet in room 303 MacLean:
lp -dp303 data.psThe only color printers I'm aware of are those in 303: the dye-sub (glossy paper) printer, color, and the bubble jet printer, hpcolor. Both do transparencies, though they take special, expensive paper. Be conservative. Most certainly, any copy shop in town will print color for you as well. One would hope that most copy shops can handle PostScript.
The Gnuplot man page is short and generally unhelpful, but it will tell you how to customize the program's appearance. This will allow you to change the default graph colors and line dotting patterns. Oddly enough, it seems these things can only be set through X resources. Thus, if you don't like the defaults, you'll have to create a .Xdefaults i file in your home directory, or get to know xrdb. As I'm sure you're aware, you may invoke it from the Unix command line by typing:
man gnuplotNote: The man page seems to be available only on HP machines in the CS department.
The official Gnuplot home page is:
http://www.cs.dartmouth.edu/gnuplot_info.html
The official source or binary distributions may be found there as well:
ftp://ftp.dartmouth.edu/pub/gnuplot/
There is a group:
comp.graphics.gnuplot
This group has a very complete FAQ at
ftp://rtfm.mit.edu/pub/usenet/news.answers/graphics/gnuplot-faq
Direct any further questions to Bob Kooima kooima@cs.uiowa.edu
This information has been gleaned from my own personal experience with Gnuplot. This FAQ is certainly incomplete and probably even incorrect in places. Please bring any blatant factual errors to my attention.