Gnuplot图形展示hadoop处理结果

一直苦恼于如何将hadoop处理的结果进行显示,有一些商业图形软件和大数据可以很好的集成如Intellicus,功能很完善图形显示也很漂亮但是目前阶段过于繁琐,而且还是收费的。还有一种是Eclipse的BIRT插件,这个工具比较好用,比较适合正式的项目开发应用。后来偶尔发现一个很好用的小工具Gnuplot,可以在window, linux各种平台上运行的,主要是应用在数学计算中的的画各种函数曲线,于是乎就打算用它作为目前的数据展示。

Gnuplot 是一种免费分发的绘图工具,可以移植到各种主流平台。它可以下列两种模式之一进行操作:当需要调整和修饰图表使其正常显示时,通过在 gnuplot 提示符中发出命令,可以在交互模式下操作该工具。或者,gnuplot 可以从文件中读取命令,以批处理模式生成图表。例如,如果您正在运行一系列的实验,需要每次运行后都查看结果图表;或者当您在图表最初生成很久以后需要返回图表修改某些内容时,批处理模式能力会特别有用。当在 WYSIWIG 编辑器中很难捕获用于修饰图表的鼠标单击事件时,您可以很容易地将 gnuplot 命令保存在文件中,六个月后将其加载到交互式会话中重新执行。

安装:

http://www.gnuplot.info/download.html


运行实例:

之前有运行过MapReduce的job求1993年到2013年之间每年的平均温度,最高温度和最低温度。在3个节点上处理1.2G的数据量总时间是6分钟。本实例没必要用那么都的数据,于是选择2012年的部分气象数据92MB,求每个月的平均温度,最高温度和最低温度。

这里贴上Reduce的代码,其他的Map和Driver类和之前的基本差不多。

@Override
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException{
long totalNum = 0;
long totalValue = 0;
long maxTemp = Long.MIN_VALUE;
long minTemp = Long.MAX_VALUE;
long avgTemp = 0;

for(IntWritable value: values){
long temperature = value.get();
totalNum ++;
totalValue += temperature;

if(temperature > maxTemp){
maxTemp = temperature;
}

if(temperature < minTemp){
minTemp = temperature;
}

}
avgTemp = totalValue/totalNum;
double avg = (double)avgTemp/(double)10;
double max = (double)maxTemp/(double)10;
double min = (double)minTemp/(double)10;

context.write(key, new Text(String.valueOf(avg) + "\t" + String.valueOf(max) + "\t" + String.valueOf(min)));
}

2012年的平均温度,最高温度,最低温度:

201201 -0.2 24.7 -21.0
201202 -0.9 26.1 -34.0
201203 5.6 30.3 -18.0
201204 5.9 32.0 -19.0
201205 11.4 35.6 -5.0
201206 14.3 39.4 -2.3
201207 17.3 40.0 0.0
201208 15.8 36.7 -18.3
201209 12.0 35.0 -18.0
201210 6.8 30.0 -14.0
201211 4.6 30.0 -11.0
201212 -1.6 26.0 -29.2

输入Gnuplot 脚本来画出2012年每个月份的平均温度,最高温度,和最低温度三条曲线图

gnuplot> set xlabel "Month"

gnuplot> set ylabel "Temperature"

gnuplot> set title "Year(2012) Monthly Temperature"

gnuplot> set xrange[201201:201212]

gnuplot> set xtics 201201,1,201212

gnuplot> plot "temperature.dat" using 1:2 w lp pt 5 title "Avg Temperature", "temperature.dat" using 1:3 w lp pt 6 title "Max Temperature", "temperature.dat" using 1:4 w lp pt 7 title "Min Temperature"

 
画出来的图形曲线如下:
Gnuplot图形展示hadoop处理结果 - spring8743 - 我的博客
 
参考资料:
http://www.gnuplot.info/  (Gnuplot官网)
http://www.ibm.com/developerworks/cn/linux/l-gnuplot/ (IBM developer works关于gnuplot的一篇)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值