This tutorial will demonstrate the use of Gnuplot on a PC. If you do not
have Gnuplot, you should get it from http://www.gnuplot.info
for your machine.
Other tutorials are available from http://www.gnuplot.info/help.html
Once you have Gnuplot installed, fire it up by clicking on the
When Gnuplot first starts on a PC, it will display plots to your screen
by default. This can be noted by the phrase " Terminal type set to 'windows' "
displayed on the screen. If this is not displayed, you must explicitly type
in "set terminal windows" (no quotes), at the gnuplot prompt:
We will first demonstrate Gnuplots built in functions. You can see which
functions are available by pulling down the Functions menu at the top of
the gnuplot window. At the gnuplot prompt type "plot sin(x)" (no quotes).
You should have a window pop open with the following:
Now, let's add some fine-tuning to this plot. At the gnuplot prompt,
enter the following five lines:
set xlabel 'x-axis'
set ylabel 'y-axis'
plot [-2*pi : 2*pi] sin(x) title "Sine Wave" with point
From the output below, you should be able to figure out what the above
To turn off the grid, you would "set nogrid", to turn off the xlabel,
you would type "set xlabel ' ' ".
Type "set" (no qutoes) at the gnuplot prompt to see all of the options
you can turn on and off, and how to use them.
Now, Let's make some plots from some data files. Let's say you have a file
with two columns, the first represents the time in seconds, the second represents
the amount of bacteria in a petri dish. Here is the data
file. For a two-dimensional plot, Gnuplot assumes the first column to be
"x-values", and the second column to be "y-values".
I will plot this by typing "plot" (no quotes), choosing Plot from the file menu
at the top of the GnuPlot window, choosing Data filename ..., and then
browsing to the location of the file "squares.dat" on my hard drive. (You could
make your own file called "squares.dat" and follow this tutorial.) I also added
"with lines" to my command, so my entire command was:
plot 'squares.dat' with lines
Notice I changed what the x-axis and y-axis say.
Now, Let's make a 3-D plot! I hava a data file with
3 columns of information. Here I use "splot" instead of plot since it it a
3-dimensional plot. Note, the first column in the data file represents x-values, the
second y-values, and the third z-values.
splot 'glass.dat' with lines
Finally, to save the above image as a ".gif" file instead of displaying it to
the screen, enter the following commands:
set terminal gif
set output 'glass.gif '
splot 'glass.dat' with lines
This will create a .gif image called "glass.gif" of the previous plot.
It will be placed in the same folder the .dat
file was located in. You can then place this image into html pages or word processor
documents for display!
Remember, the plot will not appear on the screen when you
redirect the output to a .gif file, so it may appear as if nothing has happened.