Gnuplot Examples

To use grnuplot, type gnuplot from the UNIX prompt.

Gnuplot can be run interactively, or from script files. Script files are simply ascii files that have commands written out just as you would enter them interactively. You can run a script two ways:

Usually, I test out plotting features interactively (using the help command as needed), and put the commands to generate a plot in a script file so that I can reproduce the graph at a later time. (Having a gnuplot script is great when you are debugging computational programs. You can quickly plot your output files to see if they look reasonable.)

Now for some examples. Note that lines begining with # are comments.

Making an energy plot

Suppose you want to plot the file d1.dat.
Try the following.

#set terminal postfile       (These commented lines would be used to )
#set output  "d1_plot.ps"    (generate a postscript file.            )
set title "Energy vs. Time for Sample Data"
set xlabel "Time"
set ylabel "Energy"
plot "d1.dat" with lines
pause -1 "Hit any key to continue"

This example uses the default X11 window for output. It sets the name of the plot title. Then it set the names of the x-axis and y-axis to Time and Energy (default would be X and Y). The plot command is really the key line. It plots data from a file, using column 1 and 2 as the default x and y values. The limits are set automatically, and data points are connected with lines. Some variations on the plot command are:

There are may other variations on the plot command, type help plot from more information.

Email your questions/corrections/comments

That's all for now. Please let me know if this is useful. If you have any questions that you want answered here, email me at shumway@uiuc.edu. Also, if you have any gnuplot tricks or techniques you would like to post here, let me know and I'll put them on.

Back to Phys498a Home Page


Last updated January 23rd. shumway@uiuc.edu