Intro to Scientific Computing

PHYS 27/193

Physics Department
University of the Pacific


Plotting Data from a File



Now we are getting down to it.

What we have done so is good for learning mathematics, i.e. plotting beautiful functions and seeing what they look like. We even learned to solve an equation "Graphically".

But as scientists we are often trying to learn something
about physics from an experiment that we have done.
In other words, we have some data and we what to understand what theoretical model
or mathematical relationship is indicated by this data.

We can often tell that by just looking at a plot of the data,
or in fancier language: visualizing the data. That's what we'll do now.


First, we need some data.

Open Emacs and enter the following data
(you should be able to cut and paste it from your browser window).

It is important that you have columns of ASCII (or text) numbers with "white space" in between them.
"White space" means either a single or more SPACEs (as when you hit the space bar), or a TAB.

0.0 0.24
0.5 0.66
1.0 1.56
1.5 2.05
2.0 2.80
2.5 1.74
3.0 2.54
3.5 3.36
4.0 4.61
4.5 4.44
5.0 5.61
5.5 4.68
6.0 6.72
6.5 5.97
7.0 7.07
7.5 8.38
8.0 7.44
8.5 9.34
9.0 8.12
9.5 9.97
10.0 10.54

Cd to your gp/ dir and save this file as data1.dat.

Plotting Your New Data

Now that you have some data (and have "cded" to the place where gnuplot can find it)

start gnuplot.

Type:
gnuplot> plot "data1.dat"

Be sure to include the " " s.
You need to do this anytime you refer to a "file" or "folder" on your disk, such as a data file, as I have shown in this sentence.

Your plot should look like this:




Plotting Data, Step 2

By this point you show have a plot of some little red +'s representing the data shown above and saved in data1.dat. Let's play around with this plot a bit.

One of the first things I notice is that the + in the uppermost right corner is not one of the data point in the file! That's because it is the plot symbol in the key, which in this case, is confusing since it is near other data points.

There are several ways to change this. The simplest is to just move the key:
gnuplot> set key left
gnuplot> plot "data1.dat"

Ah. Much better. You could also out a box around the key; remember how? (see Gnuplot: Page 1).

Those points are a little small. Let's change them. This time do the plot with the "with" option:
gnuplot> plot "data1.dat" with points pointtype 4 pointsize 3 linecolor 3   

Now we have Larger Blue Squares! Nice. You can abreviate that long line, as you can with most gnuplot command options and variables, by typing:
gnuplot> plot "data1.dat" w p pt 4 ps 3 lc 3   

Isn't that a whole lot easier? Try changing the "pointtype (pt), the "pointsize" (ps), and "linecolor" (lc), and see how your plot changes. You can see the various line/point types and colors by typing test. This will send a test pattern to the screen and show the things available to your screen.
gnuplot> test

To see the options available to the with command, type help plot with at the gnuplot> prompt. You'll have to hit [SPACEBAR] to page through the help pages and get back your gnuplot> prompt.




Summary

So far (gnuplot/pages1-4), we have learned the following:

You've learned a fair amount already!