next up previous
Next: List of Commands Up: Other Applications Previous: PDF and Postscript

Plotting Data

Often you will want to plot data on a graph, and there are many ways to do this. Two of the most useful are gnuplot and xmgrace. Both are extremely flexible and powerful, and can be customised quite heavily, but in general you will probably find gnuplot better for quickly plotting data and fitting functions to it, and xmgrace better for good quality output and plotting lots of different data sets on the same graph.

Whilst xmgrace has a graphical user interface, and so is relatively easy to start with, gnuplot has a command-line interface so can be a bit trickier. To plot the data in file phil.dat

gnuplot> plot 'phil.dat'

Each datum is a small diamond, but it's often easier to join them with lines as well.

gnuplot> plot 'phil.dat' with linespoints

By default gnuplot will use the first column of the file as the x data, and second column as the y. We can tell it which columns to use

gnuplot> plot 'phil.dat' using 3:2 with linespoints

One of the more useful features of gnuplot is that it will do function fitting and plotting.

gnuplot> f(x) = a + b*x
gnuplot> fit f(x) 'phil.dat' using 1:2 via a,b

The function f(x) is fitted to the data in columns 1 and 2 of phil.dat by varying the parameters a and b. The fitting is an iterative process, and at the end you will see

a               = 24.0778
b               = 12.2008

After 4 iterations the fit converged.
final sum of squares of residuals : 37.9648
rel. change during last iteration : -2.76273e-09

degrees of freedom (ndf) : 3
rms of residuals      (stdfit) = sqrt(WSSR/ndf)      : 3.55738
variance of residuals (reduced chisquare) = WSSR/ndf : 12.6549

Final set of parameters            Asymptotic Standard Error
=======================            ==========================

a               = 24.0778          +/- 2.371        (9.848%)
b               = 12.2008          +/- 0.6064       (4.97%)


correlation matrix of the fit parameters:

               a      b
a               1.000
b              -0.742  1.000

Of course we probably want to plot this.

gnuplot> plot f(x), 'phil.dat' using 1:2

The scales are a bit large, but we can change those as well

gnuplot> plot [0:3] f(x), 'phil.dat' using 1:2

There are many more commands, and you can type help at the gnuplot prompt to find out more.


next up previous
Next: List of Commands Up: Other Applications Previous: PDF and Postscript
Phil Hasnip 2007-08-23