1. ‘ GNUPLOT & ITS APPLICATIONS’
Sabyasachi Ray
Roll no.03 , Part 2
Department of physics
University of North Bengal
2. Scientists runs simulations or take
measurements. These data need to be
presented in an appealing and professional
manner.
Sometimes there are a lot of data. Sometimes
it is difficult to make the interesting features
come out right. Sometimes many plots must
be produced.
Manually doing plot with indefinitely large no.
of data are very difficult job. These
different necessity of plotting insists people
to develop some way to save time as well
as hard working.
3. GNUPLOT: a SOLUTION
There are lots of other plotting tools available
for creating 1D or 2D plots from numerical
data in different operating systems
Though many plotting tools are available now-
a-days , one of the best advantages of ‘gnuplot’
over (say) MATHEMATICA or MAPLE GRAPHS is
that it is incredibly easy to write scripts to
automatically create graphs for people from
raw data.
4. What is gnuplot?
gnuplot is a command-driven interactive function
and data plotting program. It can be used to plot
functions and data points in both two and three
dimensional plots in many different formats.
5. GNUPLOT : HISTORY
Software developer:
Original software:
THOMAS WILLIAMS,COLIN KELLEY
gnuplot 2.0 additions:
RUSSELL LANG, DAVID KOTZ, JOHN CAMPBELL
gnuplot 3.0 additions:
GERSHON ELBER,ALEXANDER WOO & MANY
OTHERS
gnuplot 4.0 additions:
HANS-BERNHARD BRӦKER, ETHANA-MERIT AND
OTHERS
6. GNUPLOT: supporting
operating system
precompiled executables and source code for
gnuplot is downloadable for
1) windows ,
2) DOS,
3) Unix,
4) Linux.
Gnuplot is preinstalled in most of the LINUX
system
7. LINUX
‘gnuplot’ is a software works in almost every
platform. I do my PROJECT WORK in
FEDORACORE 3 (LINUX) platform. As scientific
world mostly uses the LINUX platform.
8. WORLD-WIDE LINUX
The governments of many third world nations
like BRAZIL, SPAIN,CHINA,PERU,PAKISTAN and
INDIA are actively involved in promoting
LINUX and associate open source softwares.
LINUX has found its way to Cell-Phones,
desktops and office computers.
the LHC itself is controlled by LINUX
9. Installing Fedora:requirement
A pentium-class PC (at least 200 MHz for text mode;
400 MHz Pentium II for GUI)
64 Mb RAM (for text mode)
192 Mb RAM (for GUI mode)
10. Minimum hard-disk space
620Mb for minimum custom install
2.3 Gb for personal desktop
3.0 Gb for workstation
1.1 Gb for server install
A everything install requires at least
6.9Gb
11. Linux: installation
I installed fedora core 3 in a desktop.
There are different steps one should follow while
installing.
The important thing is the PARTITION of hard drive.
13. Plotting:What does gnuplot offer?
Plotting two-dimensional functions and data points in
many different styles (points, lines, error bars)
Plotting three-dimensional data points and surfaces in
many different styles (contour plot)
Algebraic computation in integer, float and complex
arithmetic
User-defined functions
Support for a large number of operating systems, graphics
file formats and output devices
Extensive on-line help
TEX-like text formatting for labels, titles, axes, data
points
Interactive command line editing and history .
14. Starting : GNUPLOT
To start gnuplot in LINUX we have to simply type
gnuplot in the command line of the linux terminal as
follows:
gnuplot
This command gives:
15. Starting : GNUPLOT
G N U P L O T
Version 4.0 patchlevel 0
last modified Thu Apr 15 14:44:22 CEST 2004
System: Linux 2.4.23
Copyright (C) 1986 - 1993, 1998, 2004
Thomas Williams, Colin Kelley and many others
This is gnuplot version 4.0. Please refer to the documentation
for command syntax changes. The old syntax will be accepted
throughout the 4.0 series, but all save files use the new syntax.
Type `help` to access the on-line reference manual.
The gnuplot FAQ is available from
http://www.gnuplot.info/faq/
Send comments and requests for help to
<gnuplot-info@lists.sourceforge.net>
Send bugs, suggestions and mods to
<gnuplot-bugs@lists.sourceforge.net>
Terminal type set to 'x11'
gnuplot>
17. Gnuplot: functions
abs(x) absolute value of x, |x|
acos(x) arc-cosine of x
asin(x) arc-sine of x
atan(x) arc-tangent of x
cos(x) cosine of x, x is in radians.
cosh(x) hyperbolic cosine of x, x is in radians
erf(x) error function of x
exp(x) exponential function of x, base e
inverf(x) inverse error function of x
invnorm(x) inverse normal distribution of x
18. Gnuplot: functions
log(x) log of x, base e
log10(x) log of x, base 10
norm(x) normal Gaussian distribution function
rand(x) pseudo-random number generator
sgn(x) 1 if x > 0, -1 if x < 0, 0 if x=0
sin(x) sine of x, x is in radians
sinh(x) hyperbolic sine of x, x is in radians
sqrt(x) the square root of x
tan(x) tangent of x, x is in radians
tanh(x) hyperbolic tangent of x, x is in radians
E.T.C.
24. Gnuplot: plotting functions
To plot functions simply one have to type: plot
[function] at the gnuplot> prompt.
say plot sin(x) to draw a first figure.
Say replot sin(x)**2 to add a second plot
Say plot sin(x),-sin(x) to plot two graphs at once.
Also one can define external function as
gnuplot> f(x)=3*x**4
gnuplot> plot f(x)
30. gnuplot: Plotting data
One can display plot data by typing:
gnuplot> plot "force.dat" using 1:2 title 'Column',
"force.dat" using 1:3 title 'Beam’
If the data are in multiple data files. In this case
one should plot by using a command like:
gnuplot> plot "fileA.dat" using 1:2 title 'data A',
"fileB.dat" using 1:3 title 'data B'
31. gnuplot: plot command
customization
Plots may be displayed in one of the styles: lines,
points, linespoints, impulses, dots, steps, fsteps,
histeps, errorbars, xerrorbars, yerrorbars,
xyerrorbars, boxes, boxerrorbars, boxxyerrorbars,
financebars, candlesticks or vector To specify the
line/point style use the plot command as follows:
gnuplot> plot "force.dat" using 1:2 title 'Column'
with lines,
"force.dat" u 1:3 t 'Beam' w linespoints
32. gnuplot: PRINTING
One can create a PostScript file of plot by using
the following :
gnuplot> set terminal postscript
gnuplot> set output "my-plot.ps"
gnuplot> plot sin(x)
33. gnuplot: Commands to Quit
exit or quit command terminates gnuplot.
Once one quit gnuplot, all of setting one made
will be lost.
To save the current setting, use save command
followed by a file name in which parameters and
functions one defined are stored.
gnuplot overwrites internal parameters in that
file without any warnings.
34. gnuplot: Commands to Save
Parameters
gnuplot> save "savefile.plt"
the saved file is a usual text file.
one can edit the contents with a text editor.
To draw a graph again with this file, we use the
load "savefile.plt" command at the gnuplot
command-line-
gnuplot> load "savefile.plt"
35. application: gnuplot
Now different kind of plotting and fitting that
I made are shown and explained in the next
coming slides.
36. simple ploting using sin(x)
gnuplot> set terminal postscript
gnuplot> set output 'sin.pdf'
gnuplot> plot sin(x)
37. simple ploting using sin(x)
To set the X range 0 to 5, [0:5]
gnuplot> plot [0:5] sin(x)
38. simple ploting using sin(x)
gnuplot> set angle degree
gnuplot> set xrange[-270:270]
gnuplot> plot sin(x)
40. gnuplot: different styles available
Now say some data file named "output.dat"
contains some nature as shown below.
gnuplot> plot "output.dat" title ‘style1’ with lines.
44. gnuplot: plotting of two sets of
data from a single data file
The taken data file was named ‘ lateral density.txt’
#lateral density.txt
gnuplot> set terminal postscript
gnuplot> set output 'lateral density.pdf'
gnuplot> set logscale
45. gnuplot: plotting of two sets of
data from a single data file
gnuplot> set title 'PLOTTING OF TWO SETS OF
DATA FROM A DATA FILE‘
gnuplot> set xrange [8:75]
gnuplot> set yrange [0.1:3.0]
gnuplot> set xlabel 'CORE DISTANCE(meter)'
gnuplot> set ylabel 'DENSITY (particle/square meter)'
gnuplot> plot 'lateral density.txt' u 1:3 title
'experimental density' w p 3,
> 'lateral density.txt' u 1:2 title 'theoretical density' w p
4
47. gnuplot: plotting of two sets of
data from a single data file
gnuplot> replot 'lateral density.txt' u 1:2 w l title
'theoretical graph‘
48. gnuplot: plotting of two sets of
data from two different data
files and comparing them
two data file are ‘absorptionrade’ & ‘absorptionsr’
gnuplot> set terminal postscript
Terminal type set to 'postscript'
Options are 'landscape noenhanced monochrome blacktext
dashed dashlength 1.0 linewidth 1.0 defaultplex
palfuncparam 2000,0.003
butt "Helvetica" 14'
gnuplot> unset logscale
gnuplot> set output 'absorption plot.ps'
gnuplot> set xlabel 'Corrected thickness (mg/cm^2)'
gnuplot> set ylabel 'counts/minute'
gnuplot> set title'BETA ABSORPTION CURVE'
49. gnuplot: plotting of two sets of
data from two different data
files and comparing them
gnuplot> plot 'absorptionrade' w p 3,'absorptionsr'
title'comparing two sources'
50. gnuplot: linear curve fitting
The data file that I choose for this case is:
Age.txt
gnuplot> set output 'age.ps'
gnuplot> set title 'LINEAR CURVE FITTING FOR
DATA FILE USING GNUPLOT'
gnuplot> set label 'z=zenith angle' at 1.1 ,1.6
51. gnuplot: linear curve fitting
gnuplot> set xrange[1:1.5]
gnuplot> set yrange[1.25:1.65]
gnuplot> set xlabel 'sec(z)'
gnuplot> set ylabel 'SHOWER AGE'
gnuplot> f(x)=(m*x)+c
gnuplot> m=1.4;c=-0.13
gnuplot> fit f(x) 'age.txt' u 1:2 via m,c
After 4 iterations the fit converged.and it is
shown on the screen
52. gnuplot: linear curve fitting
gnuplot> set label 'f(x)=m*x+c,m=0.98,c=o.30' at 1.3,1.5
gnuplot> plot 'age.txt' u 1:2:3 w yerrorbars title
'f(x)=m*x+c',
> f(x) title 'fitted curve‘
these commands will produce :
53.
54. linear curve fitting of more than
one plot in a single graph:
My data file is ‘test.txt’ that I used in my this
particular plotting:
gnuplot> set terminal postscript
gnuplot> set output 'manyplot.ps'
gnuplot> set title ' PLOTING & LINEAR FITTING OF
MORE THAN ONE DATA SETS AT A TIME'
gnuplot> set xlabel 'sec(z)'
gnuplot> set ylabel 'shower age'
gnuplot> set label 'z is the zenith angle' at 1.1,1.5
gnuplot> set xrange[1:1.4]
gnuplot> set yrange [1:1.55]
55. gnuplot> f1(x)=a1*x+b1
gnuplot> a1=-2;b1=3.28
gnuplot> fit f1(x) 'test.txt' u 1:2 via a1,b1
the fitting command for 2nd set of data points
are:
gnuplot> f2(x)=a2*x+b2
gnuplot> a2=0.067;b2=1.173
gnuplot> fit f2(x) 'test.txt' u 1:4 via a2,b2
the fitting command for 3rd set of data points
are:
gnuplot> f3(x)=a3*x+b3
gnuplot> a3=2;b3=-1.17
gnuplot> fit f3(x) 'test.txt' u 1:6 via a3,b3
56. linear curve fitting of more than
one plot in a single graph:
gnuplot> plot 'test.txt' u 1:2:3 w yerrorbars title' Fe',
> f1(x) title 'y=0.31*x+0.95',
> 'test.txt' u 1:4:5 w yerrorbars title ' Mixed',
> f2(x) title 'y=0.17*x+1.07',
> 'test.txt' u 1:6:7 w yerrorbars title ' proton',
> f3(x) title 'y=.26*x+.83'
These produce:
57.
58. non-linear curve fitting
For non-linear curve fitting I take the data file
'lateral density.txt'
gnuplot> set output 'nonlinear.ps'
gnuplot> set logscale
gnuplot> set xrange [8:75]
gnuplot> set yrange [0.1:3.0]
gnuplot> set xlabel 'CORE DISTANCE(meter)'
gnuplot> set ylabel 'DENSITY (particle/square meter)'
gnuplot> set title 'NON-LINEAR FITTING (more than
one line)'
gnuplot> set label 'y=(a+b*x+c*x**2+d*x**3)**3' at 30,1
59. non-linear curve fitting
gnuplot> f1(x)=(a1+b1*x+c1*x**2+d1*x**3)**3
gnuplot> a1=10;b1=20;c1=-4;d1=6;
gnuplot> fit f1(x) 'lateral density.txt' u 1:2 via a1,b1,c1,d1
gnuplot> f2(x)=(a2+b2*x+c2*x**2+d2*x**3)**3
gnuplot> a2=1;b2=20;c2=-4;d2=6
gnuplot> fit f2(x) 'lateral density.txt' u 1:3 via
a2,b2,c2,d2
60. non-linear curve fitting
gnuplot> plot 'lateral density.txt' u 1:2 title 'theoretical' ,
> f1(x) title 'a=1.77,b=-0.05,c=0.0011,d=-8.39e-6' ,
> 'lateral density.txt' u 1:3 title 'experimental' ,
> f2(x) title 'a=1.81,b=-0.06,c=0.001,d=-6.37e-6'
61. 3-DIMENSIONAL PLOT USING
GNUPLOT:
gnuplot> set output '3d.ps'
gnuplot> set title 'the function choosen is sin(x*y/20)'
gnuplot> set xr [-10:10]
gnuplot> set yr [-10:10]
gnuplot> set zr [-1:1]
gnuplot> set xlabel 'x-axis'
gnuplot> set ylabel 'y-axis'
gnuplot> set zlabel 'z-axis'
gnuplot> splot sin(x*y/20)
63. The advantages
The results are repeatable. This is very useful if one
needs many similar graphs, or if one potentially needs
to redo graphs with updated data.
Plots can be produced automatically. Sometimes
plots take a long time, especially if there are much
data to be processed.
Plots can be produced on a remote supercomputer,
written into a file, and then displayed locally. The data
do not need to be transferred.
For a quick look at small datasets there are many
tools.
For serious work gnuplot is one of the best.
64. Disadvantages
Gnuplot has a limited set of line and point styles.
Gnuplot cannot output symbolic equations or
formula and labels in most output formats.
Gnuplot does a poor job of making contour plots.
This is very hardworking job to remember all the
commands all time.
65. CONCLUSSION:
In gnuplot there are many other integrated
facilities like animation. But due to shortage of
time I can not learn them.
If I get an opportunity to use gnuplot in
future, this project will surely help me lot.
More over I used this opportunity to learn little
bit about LINUX that would also help in advanced
studies.
66. Bibliography
1> GNUPLOT 4.2 - A Brief Manual and Tutorial
Department of Civil and Environmental Engineering
Edmund T. Pratt School of Engineering
Duke University - Box 90287, Durham, NC 27708-0287
2> www.gnuplot.info.
3> G N U P L O T
Version 4.0
4> ‘fast track to LINUX, a beginners guide’ –digit February 2009.
5> perfect Set up- Fedora Core 3 |HowtoForge-Linux Howtos and Tutorials
www.howtoforge.com/perfect_setup_fedora_core_3
6> book: BIBLE OF LINUX
7> http://www.duke.edu/~hpgavin/gnuplot.html.
8> http://www.cs.uni.edu/Help/gnuplot/
9> Gnuplot Short Course- Tim Langlais
10> http://t16web.lanl.gov/Kawano/gnuplot/index-e.html