Thursday, November 28, 2013

GNUplot Tutorial for beginners (on Linux)

GNUplot is a versatile graphing and plotting tool which is more than sufficient for all your graphing needs. Some of the impressive features that I appreciate are:
  • It provides great flexibility when you want a script to automate your graphing. I had to run several hundred simulations and plot the data for each and every one of them. Without GNUplot, i could not have done it.
  • It can produce graphs in many different formats (both in vector and raster formats)
  • It has nice curve-fitting tools
  • It is free!
Here is a very simple tutorial for beginners that should get you started. If you are looking at something that has a more exhaustive coverage, you can check this: duke.edu GNUplot tutorial  or go to official GNUplot site for help.
So, lets get started.

Download and install Gnuplot:
$ sudo appt-get install gnuplot
Start using gnuplot:
$ gnuplot
Now you enter into a gnuplot command prompt

Plot a line plot from 2 columns (column 1 and column 2) of a .csv file

gnuplot> plot "filename.csv" using 1:2 with lines
Save Graph as a jpeg
Type the following commands before you plot the graph that you need to save (note: jpeg file will be saved in the current directory)
gnuplot> set terminal jpeg
gnuplot> set output ‘filename.jpeg’


If you wish to save to a specific location, add the location like this:
gnuplot> set output ‘../location/filename.jpeg’
To avoid title inside the plot
gnuplot> plot "filename.csv" using 0:1 with lines notitle

To add Title, xlabel and ylabel
This is similar to matlab. Enter these commands before you plot the graph.
gnuplot> set title "your title”
gnuplot> set xlabel "your xlabel”
gnuplot> set ylabel "your ylabel”
To put your gnuplot commands into a bash script
refer to this example:
TRAFFIC=(random transpose1 transpose2 bitreversal butterfly shuffle) #synthetic traffic patterns
for t in $(seq 0 5)
do
 #plot graphs 
        gnuplot <<- 1:2="" applied="" cycles="" cylce="" done="" eof="" exp="" flits="" hroughput="" in="" jpeg="" lines="" load="" node="" notitle="" output="" packets="" per="" plot="" pplied="" pre="" set="" t="" terminal="" thru_plot.jpeg="" title="" traffic:="" using="" vs="" with="" xlabel="" ylabel="">

Note that EOF is only a label. It could be any other name as you wish. That’s it for now. I think this should form a good basis for anyone new to GNUplot and help you get going.

No comments:

Post a Comment