Gnuplot Tutorial
Gnuplot Tutorial
This tutorial guides you to plot data files and fitting functions using gnuplot. For a more detailed tutorial refer the
on-line link:
http : / /www. duke . edu /˜ hpg a vin / g n u p l o t . html
I. PLOTTING
” H e l v e t i c a ” 14 ’
g nuplo t> r e p l o t
g nuplo t> q u i t
Now will have a postscript file called ’file.ps’. You can convert a postscript file to a pdf file using the following
command:
p s 2 p d f f i l e . ps
This creates a pdf file called ’file.pdf’.
II. FITTING
We are going to fit a straightline to the data in the sample file called ’file.dat’. Once again open gnuplot and plot
the file. If there are both linear and non-linear regions, adjust the range of x so that you can see only the linear part.
Then use the following commands:
g nuplo t> f ( x ) = a ∗x + b
g nuplo t> f i t f ( x ) ‘ f i l e . dat ’ u s i n g 1 : 2 v i a a , b
This would give the value of a and b and the results are stored in a file called fit.log in your current working directory
(the result is also displayed immediately on the screen).
Suppose we want to plot the log of the columns in the data file, we could do the following for natural logs
g nuplo t> p l o t ” f i l e . dat ” u s i n g ( l o g ( $1 ) ) : ( l o g ( $2 ) )
or to the base10
g nuplo t> p l o t ” f i l e . dat ” u s i n g ( l o g 1 0 ( $1 ) ) : ( l o g 1 0 ( $2 ) )
Another example:
g nuplo t> p l o t ” f i l e . dat ” u s i n g ( $1 ) : ( $2−$1 )
where the y axis is the difference between the second and the first columns.