免费注册 查看新帖 |

Chinaunix

广告
  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2342 | 回复: 0
打印 上一主题 下一主题

NS2进阶实例9--Gnuplot工具的应用实例 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-11-10 22:55 |只看该作者 |倒序浏览

     这两天因为准备一个会议的数据,所以利用NS2的Gnuplot工具做了一些数据绘图工作,于是我就对gnuplot 工具的使用做一下的整理,并且给出自己的数据处理过程,仅供参考,也方便自己以后的查询! 哈哈   (很多书籍和电子资料,或网页什么的,介绍时往往有厚重、繁琐的历史发展等信息,我就不再做了,我希望写成使用时的一个简单的、即学即用的备忘录哦! 哈哈)

     关注点:
     gnuplot的基本使用和命令集;
     一次科研的数据处理实例!
   
A. gnuplot

    以下只是我认为的很有用的基本命令,将来有更多的实用经验时,我将进一步完善!
gnuplot和xgraph, 存储的文件都可以是如下形式:
0.5  10
1.0  15
1.5  20
... ...

0.使用规范
使用gnuplot时,可以一项一项地设置,逐步修改绘图环境;
使用命令: $gnuplot  从而进入  gnuplot>  模式,即可开始使用命令开始绘图;
假设有文件 file1, file2
则绘制基本命令为: gnuplot> plot "file1", "file2"  //还有更多的文件是,分别用逗号隔开
不同文件的数据,软件会采用不同的颜色区分,效果很好!

1. 坐标轴的控制
   坐标轴“量程”设置     set xtics $start,$incr,$end    // ytics 类似
                        set xrange [$xmin:$xmax]       // yrange
   坐标标注:           set xlabel "Simulation time"   //  ylabel类似
   设置图片的标题:       set title "TITLE"
   
2.画线段
     set arrow {tag} {from sx,sy}{,sz} {to sx,sy}{,sz} {{no} head}
  设置一条线条id 为: tag, 从起点到终点, 是否带箭头;
  其中的{} 表示该选项是可选的!
  unset arrow {tag}     //删除 tag 线条
  
3.线条类型的定义 plot "FILE" with
  选项的可用值:
     lines,     points,   linespoints,   impluses(引垂线到X轴)
  dots,      steps,   
  errorbars, boxes,    boxerrorbars
  
4.输出
gnuplot> set terminal gif  
gnuplot> set output "file.gif"
gnuplot> replot      //产生了一个 file.gif  的图片


实例演示:Node A1, Node A2, Node A3, Node A4文件的数据:
1 0.1397
2 0.1731
3 0.1624
4 0.1927
5 0.1164
6 0.134
7 0.164
8 0.1648
9 0.1894
10 0.1722

1 0.1792
2 0.1758
3 0.1789
4 0.15
5 0.1736
6 0.1829
7 0.1915
8 0.1765
9 0.1577
10 0.1316

1 0.1314
2 0.1043
3 0.129
4 0.1189
5 0.1046
6 0.087
7 0.1053
8 0.1059
9 0.1068
10 0.0682

1 0.1066
2 0.0796
3 0.0874
4 0.1065
5 0.0778
6 0.0761
7 0.084
8 0.0953
9 0.082
10 0.0822

       文件Zhu--A1,Zhu--A2,Zhu--A3,Zhu--A4中的数据:
1 0.924
2 0.972
3 0.961
4 0.9983
5 0.8362
6 0.9069
7 0.841
8 0.9934
9 0.9828
10 0.87

1 0.9432
2 0.925
3 0.9299
4 0.8408
5 0.9087
6 0.964
7 0.9934
8 0.906
9 0.8692
10 0.9052

1 0.8314
2 0.8022
3 0.6945
4 0.704
5 0.7824
6 0.6456
7 0.6672
8 0.7344
9 0.7032
10 0.6332
  
1 0.6778
2 0.6267
3 0.5813
4 0.6593
5 0.5782
6 0.5406
7 0.5558
8 0.5645
9 0.6118
10 0.559


运行命令:
gnuplot> plot "Node A1" with linespoints,"Node A2" with     linespoints,  "Node A3" with linespoints,  "Node A4" with linespoints
gnuplot> set terminal gif
gnuplot> set output "file.gif"
gnuplot> replot

     
gnuplot> plot "Zhu--A1" with linespoints,"Zhu--A2" with     linespoints,  "Zhu--A3" with linespoints,  "Zhu--A4" with linespoints
gnuplot> set terminal gif
gnuplot> set output "zhu.gif"
gnuplot> replot

效果图:
     



改进图片的命令:
      
gnuplot> set title "Grey Projection for Node A1-A2-A3-A4"
gnuplot> set xlabel "Simulation time"
gnuplot> set ylabel "Values"
gnuplot> set yrange [-0.3:0.23]
gnuplot> plot "Node A1" with linespoints,"Node A2" with     linespoints,  "Node A3" with linespoints,  "Node A4" with linespoints
gnuplot> set terminal gif
gnuplot> set output "GreyProjection.gif"
gnuplot> replot

gnuplot> set title "Main attibutes for Node A1-A2-A3-A4"
gnuplot> set xlabel "Simulation time"
gnuplot> set ylabel "Values"
gnuplot> set yrange [-0.2:1.1]
gnuplot> plot "Zhu--A1" with linespoints,"Zhu--A2" with     linespoints,  "Zhu--A3" with linespoints,  "Zhu--A4" with linespoints
gnuplot> set terminal gif
gnuplot> set output "zhu.gif"
gnuplot> replot

效果图:



  


(哈哈,就这样哦,比较简单的命令使用啊!)





本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/105477/showart_2091176.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP