Thursday, September 5, 2013

Plotting graphs in NS2


For graph designing their are many tools in NS2 like xgraph, trace graph, gnuplot etc and in windows environment there is a good graph plotter called sigmaplot. They can be easily downloaded from internet. 
 
For NS2 on Linux, Gnu plot is good and easy. I would recommend you to use gnuplotif using Linux as it is more flexible than tracegraph and xgraph.
 
Fig: Sample Xgraph plot
STEPS for use and design for gnuplot:
 
1. If you are using NS2 on Linux system then GNUPLOT will be there by default. If not available, you can directly install it from ubuntu software center. Alternatively you can download it from
http://sourceforge.net/project/showfiles.php?group_id=2055 
you will need .tar.gz for linux and .zip for windows. 
 
2. Refer to the following links for installation steps:
         http://homepage.mac.com/marco_coisson/gnuplotGUI/getting_gnuplot.html

         http://www.sarcheck.com/gnuplot/billh.htm
 
         http://www.duke.edu/~hpgavin/gnuplot.html   (GNUPLOT TUTORIAL)
 
 
3. After confirming installation, update the environment variable in bash file.
 
4.Following files will be related with your work
    a. Graph.p       (code file for gnuplot)
    b. Graph.tr      (trace file from which gnuplot will take readings for plotting a graph-- you have to take your readings from your code. First column is always X-axis and second column is Y-axis and son on )
    c. Graph.eps     (actual graph image file --can be generated after running the graph.p file --. It is eps file extension. You can only open in linux . If windows you can open it through IRFAN VIEW software  otherwise ADOBE ILLUSTRATOR can also open this file on windows)
 
5. Now put the graph.p file in the folder where your graph.tr file (yours) is available and from terminal window go to that destination and just write GNUPLOT on terminal window you will get GNUPLOT> .
 
6. Please also check the trace file path in Graph.p file. It is necessary to provide file path there in code file.
 
7. Just write GNUPLOT> load "graph.p"
 
8. and you will have a graph. 
 
" Congratulations on your having a graph successfully"
 
9. you can exit from gnuplot through EXIT command.
 
10.For remaining commands for Graph plottiong, you have to explore its tutorial, mailing list for ns2 (I recommend you to join the mailing list of linux.
   Following links can give you much information you need. 
 
     http://t16web.lanl.gov/Kawano/gnuplot/index-e.html
 
     http://www.gnuplot.info/
 
============== SAMPLE FILE FOR GRAPH.P ==============
 
set title "XYZ"
set xlabel "SEC(Seconds) "
set ylabel "BW"
set xrange [0:1300]
set yrange [0:110]
#set multiplot
#set size 0.5, 0.5
#set origin 0.0, 0.5
 

set grid
set boxwidth 20
#plot "/home/XYZ/ns-allinone-2.33/ns-2.33/mygrid/graph/abc.tr"  using 1:2 with lines lt 1 lw 2 title 'My Work'
plot "/home/XYZ/ns-allinone-2.33/ns-2.33/mygrid/graph/abc.tr" using 1:2 title 'Previous Work' with linespoints , \
   "/home/XYZ/ns-allinone-2.33/ns-2.33/mygrid/graph/abc.tr" using 3:4 title 'My Work' with linespoints

   
#set tmargin 0
#set bmargin 0
   
set term post eps enhan "Helvetica" 60   
set out "combine-curve-time.eps"
#set nomultiplot
First row represents X axis and second row represents Y axis ====================================== TRACE FILE format ===================== 10 9 30 12 50 27 70 28 90 33 110 39 130 43 150 44 170 48 190 52 210 57 320 58 330 60 370 65 450 66 470 68 490 75 530 79 550 81 1280 100 ================================= Hope this helps.