Gnuplot
From UC_Chemistry
Contents |
Data Fitting
Fitting your data with a function. Suppose you have file force.dat containing two columns of data (x and y). Let's fit the data with linear function f1 and initial guess of parameters.
$ gnuplot gnuplot> f1(x) = a1*x +b1 gnuplot> a1 = 300; b1 = 0.005; gnuplot> fit f1(x) 'force.dat' using 1:2 via a1, b1
Surface Plots
If you have a function of two variables f(x,y) save the data in file mydata in the following format
x0 y0 f
x0 y1 f
...
x0 yn f
x1 y0 f
x1 y1 f
...
x1 yn f
...
Having mydata you can plot surfaces as
gnuplot> set style data lines gnuplot> splot 'mydata'
XY plot options
set title 'mytitle' set xrange [0.001:0.005] set yrange [1:2] set xlabel "my xlabel" set ylabel "my ylabel" set label 1 "high" at 0.002,1.5
subscript, superscript and greek letters
set xlabel "t_{1/2}"
set ylabel "x^2"
set title "{/Symbol a}decay"
multi-plot
p "decay1.dat" u 1:2 t "alpha decay", "decay2.dat" u 1:2 t "beta decay", "decay3.dat" u 1:2 t "gamma decay"
Terminals
You've probably noticed that gnuplot always outputs (by default) to an X11-window. This can be changed with the set term command, instructing gnuplot to write its output to a file instead.
set term png medium size 800,600 set out "bob.png" replot
will output a fairly ugly-looking png file of your plot. I think this is because most of the development has gone into the ps terminal, where some nice fonts are (or should be) avaialble.
set term postscript enhanced color solid lw 2 "Times-Roman" 27 set out "bob.ps" replot
This is the current "best-practices" terminal I have found so far. You will probably have to run the GIMP to make it the right size and/or make the background transparent.
Notations
- l = lines
- p = points, plot
- d = dots
- t = title
- w = with
- u = using
- lw = line width
- lt = line type
- xr = xrange
- [a:b] = interval between a and b
- 1:2 = the first and second column at data file
- pi = 3.14159265358979
