Gnuplot


After struggling with Algorithm programming assignmnet finally found sometime to write about a useful linux utility called GNUPLOT .

This piece of software enables you to draw different types of graphs . Got to learn about this when i was expected to plot the running time of different algorithms.

This software has predefined functions to draw various types of curves .Inaddition to it lets you plot graphs for a given values

To start gnuplot type gnuplot in shell type gnuplot. After the shell displays
gnuplot > type in the following options which are optional .

To Create a Title for the Graph : set title ” title name”
To put a label on X axis : set xlabel “xlabel name”
To put a label on Y axis : set ylabel :ylabel name”
To enable GNUPLOT automatically set range : autoscale
To a put a label at a particular point : set label “label name” at x,y
To plot using log axes : set logscale
To plot using log axes on y axis : set logscale y

After setting this , to plot the graph

Rather than giving the syntax i will give u can example which will be more clear

plot “mergesort.dat” using 1:2 title “MergeSort” with line,”selection.dat” using 1:2 title “Selection Sort” with line

mergesort.dat –> is the file which contains the values to plot
1:2 –> take first column on x axis and second column on y axis
title “MergeSort” –> The curve has the label MergeSort
with line –> The after points are plotted to join them by line include this phrase

Contents of mergesort.dat

#n #seconds
10000 0.005235
20000 0.011075
30000 0.017364
40000 0.023398
50000 0.022942
60000 0.037120
70000 0.043210

Contents of selection.dat
#n #seconds
10000 0.169516
20000 0.597250
30000 1.393896
40000 2.421752
50000 3.708825
60000 5.367077
70000 7.270945

All steps couple together

gnuplot > set xlabel “number of items”
gnuplot > set ylabel “seconds”
gnuplot > title “MergeSort vs Selection Sort”
gnuplot > plot “mergesort.dat” using 1:2 title “MergeSort” with line,”selection.dat” using 1:2 title “Selection Sort” with line

The following will display the below graph

MergeSort Vs Selection Sort

This was a very short tutorial displaying one of its functionality . For advanced tutorial just Gooooogle for it!!!!!!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: