0% found this document useful (0 votes)
6 views3 pages

GNUPLOT Data Plotting Guide

The document provides a guide on using GNUPLOT for plotting mathematical functions and data files. It includes syntax examples for plotting sine and cosine functions, as well as how to plot data from files, and compares simulated data with expected functions. Additionally, it explains how to save plots as image files and encourages users to explore more features of the software.

Uploaded by

deepakkanhar37
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

GNUPLOT Data Plotting Guide

The document provides a guide on using GNUPLOT for plotting mathematical functions and data files. It includes syntax examples for plotting sine and cosine functions, as well as how to plot data from files, and compares simulated data with expected functions. Additionally, it explains how to save plots as image files and encourages users to explore more features of the software.

Uploaded by

deepakkanhar37
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Block 3 Laboratory Manual

Syntax Output
> plot [-2*pi:2*pi][-
1.1:1.1] sin(x) with
points,cos(x) with lines

plots and displays sin(x) with


points and cos(x) with line in the
range - 2p £ x £ 2p ,
- 1.1 £ y £ 1.1

You can also plot functions that are not inbuilt by typing them into the
command line. Let us see an example of this.

Syntax Output
> plot [-1;1][0:4.1]
4*x*x with linespoints

plots and ddisplays y = 4xx 2 (line


and points) in the range
- 1 £ x £ 1, 0 £ y £ 4.1

Let us now see how we can plot data files.

2.3 PLOTTING FROM DATA FILES


Notice that you have created a data file in Example 1.3 for cos(x) . If you want to
plot this data file using GNUPLOT. In the table below we describe how to plot a
data file. We indicate the syntax and the output. We can set range, x and y zero
axes, x and y axes labels and all other attributes(line styles, plot styles like
points, linespoints etc.) in exactly the same way as we have in Sec. 2.2. Since
data files are stored in particular directories we must first change the directory to
the one in which we have stored the data file. We can do this using the command
> cd '<directory-name>'

The address of the relevant directory can be pasted inside the single quotes.
Suppose that you have stored your data file [Link] in the directory F:\C
Programs. You can then change directories as follows:
>cd ' F:\C Programs'

Once you are located in the correct directory which has your data file, you can
follow the commands shown below to plot your data from the data file.
34
Experiment 2 Introduction to Plotting Software

Syntax Output
> plot [0:pi][-1.1:1.1]
'[Link]' with points

plots the data file ‘[Link]’


which contains the values of
cos(x) at 30 equally spaced
points in the range 0 £ x £ p ,
with points generated in a C
program(Example 1.1)

We can also plot a data file and a function in the same graph. This is useful if we
want to compare how the data generated in a simulation compares with the
actual expected functional form. In the example below we plot the data generated
for cos(x) in the data file [Link] with the inbuilt function cos(x).

Syntax Output
> plot [0:pi][-1.1:1.1]
'[Link]' with points,
cos(x) with lines

plots the data file ‘[Link]’


(points)which contains the values
of cos(x) at 30 equally spaced
points in the range 0 £ x £ p ,
generated in a C
program(Example 1.1) and the
function cos(x) in the same
range(lines)

Let us check out another example. Consider the data file generated for
radioactive decay in Experiment 9. The data file contains the time t from 1 to 67
time steps, in which the number of atomic nuclei, N(t) in the sample reduces from
3000 to one. The radioactive decay law N(t ) = N0 exp( -lt ) , with the parameters
N0 = 3000 ; l = 0.1.

Syntax Output
> plot [0:100][0:3100]
'[Link]' with points,
3000*exp(-0.1*x) with
lines

plots the data file ‘[Link]’


(points) and the function
y = 3000 exp( -0.1t ) in the same
range(lines)

35
Block 3 Laboratory Manual
The plot created in GNUPLOT can be saved as an image file. In Windows you
can click on the tiny downward arrow on the gnuplot window which has the plot
(Fig. 2.2a) which gives us the options of Copy to Clipboard/Print/Export to
PDF/Export to SVG/Export to Image. You can select the option you want to save
the plot.

(a)
(a ((b)
b)

Fig. 2.2:
2.2
2.2: Sa
.2 Saving
ng the
he p
plot.
t.
With this
Wi s we come
com
come e to end
end of
of this
this very
ver
very brief description
y br desc
de scri
script
ptionn of GNU,
GNU
G NU, wh which
whic
ich
ic covers
h cove
vers
rs oonly
onl
nly
nly
a sm fraction
small fr
frac
action of what
tion what can be donedo wit with
ith this
th software. Those of you who are
interested
intere
in rested
ed may ay like
e to download
downl
d nload d GNUPLOT
GNUP
GN UPLO
LOT T an
and te
test ut the
st out the different
dififfe
d ferent kinds
rent kin
inds o
off
plots that
pl at can
can b be created
eated with
crea
cr ea th iit.

36

You might also like