gnuplot Tutorial

by Erik Huizing




The following is a tutorial on how to use gnuplot to generate some simple graphs. It is assumed you have a datafile with output in the following format:
0 3
1 4
2 5
3 6
4 9
5 10
6 12
7 18
8 22

0 32
1 41
2 51
3 64
4 96
5 102
6 123
7 181
8 221

Note the newline between the two sets of data

To run gnuplot, simply type gnuplot at the prompt. You will be presented with a gnuplot> prompt. This is where you issue commands to gnuplot. At any time, you can ask gnuplot for help by typing help at the prompt.

For your first assignment, these commands will suffice:
gnuplot> set output "graph.ps"
gnuplot> set terminal postscript
gnuplot will respond something like "Options are..."
gnuplot> plot "datafile" with lines
The first line sets the output file name to graph.ps. Use ghostview to view and print this file.

The next line sets the format of the output to postscript, which you can send to the printer on the first floor (provided you've bought paper for it)

The last line actually does the plotting, and saves it to the file. Using the data above, the graph looks like this:


Etc...

  1. Gnuplot has alot of other options (colored and dashed lines as well). One way to achieve this is to save each set of data in a seperate file, the issue the command plot "data1" with lines, "data2" with lines, "data3" with lines instead.

  2. Gnuplot also accepts scripts. Enter all the commands you wish to issue into a file. Say the file 'script' contains the following:
      set output "mygraph.ps" set terminal postscript plot "datafile" withlines
    gnuplot will run these commands if you tell it to:
    huizing@cse% gnuplot script
    

Troubleshooting

    If the graph apears to jump all over the place, you forgot to include a blank line between the sets of input.

    If you receive some X11 error, there's probably a problem with your .login file. Move it elsewhere, and re-login.


This page and contents maintained by Erik Huizing