Physics 3730/6720 Lab Exercise

PHYCS 3730/6720 Lab Exercise

References: The gnuplot links above take you to the manuals. When you run gnuplot you also have access to built-in help. For today's exercises you will find the built-in help more efficient.

(Exercise courtesy Ben Bromley.)

Exercise 1.

Open up gnuplot and look at the main help page by typing ?. Then, get help with gnuplot's plot command by typing ?plot. Scroll down the help pages until you find some "examples" of different plotting modes. Try plotting sin(x) versus x with gnuplot.

Nothing to hand in.

Exercise 2.

Create a two-column data file with x-y coordinates of several points. This can be done with emacs or even a redirection of your shell's cat function output, e.g.,

cat > file.dat
1 0.0
2 1.0
3 3.14
(the ^D => CTRL-D means end-of-file, that is, stop taking input and finish the output, in this case to the file file.dat).

Start up gnuplot and plot the points in the data file, using the syntax

plot 'file.dat'
Next try the following variations of the plot command:
plot 'file.dat'
plot 'file.dat' pt 4
plot 'file.dat' with lines
plot [-5:10] [-1:5] 'file.dat' with lines
plot 'file.dat' using ($1*$1):(sin($2)) 
plot 'file.dat' using ($1*$1):(sin($2)) with points pt 3
Notice that the size of the points is small. type ?points to see how to change the size.

In your answer file Mylab03.txt under the heading "Exercise 2", give the command for plotting the first number on each line of file.dat as the x value and the cube of the second number on each line as the y value using fairly large (at your discretion) plus signs. (That is, let x be the first number on each line and the new y be the cube of the second number.)

Exercise 3.

Using emacs, create a file file.gpl. Copy into this file one of the gnuplot commands that you used to plot the data file in Exercise 2. Tell gnuplot to execute the command(s) in this file by starting up gnuplot and typing

load "file.gpl"
The quotes are necessary -- consider this to be a peculiarity of gnuplot.

Now, you can generate hardcopy of your plot by typing these lines:

set terminal postscript
set output ""
These setting apply to all plot commands that come afterwards, so to generate the file you must then run (or rerun) the plot command or the load command after you type these lines. The first sets the kind of "terminal" to which gnuplot sends output, and the second line further specifies properties of this terminal -- in this case a property of output to a postscript file is its filename.

Get out of gnuplot with the quit command. View your postscript document using the gv utility,

You may notice that if you specify a point type number for Postscript output you get one symbol and with the same number for terminal output you get a different symbol. This is a bug in our current version of gnuplot.

The gnuplot command

set terminal X11
resets the plotting device to your console X-window.

Finally, try putting the commands to generate the postscript file at the top of the file file.gpl. This means you can now generate the postscript file simply by using the load command.

After these final changes, copy your file.gpl file to your answer file Mylab03.txt under the heading "Exercise 3" for handing in.