Ubuntu下应用Gnuplot进行数据的可视化


GNU/Linux提供了进行数据可视化的很多开源解决方案。 这些解决方案不仅能将数据转换成示意图,图表和特定的图像,还能对数据进行过滤和精简以使其更加有用。Gnuplot是最古老的可视化程序之一,也是最好用的。今天在《GNU/LINUX环境编程》中看到了,学习了一下,以下就做个学习笔记吧。

1,安装Gnuplot

如果你的电脑里没有Gnuplot , 可以用以下的命令安装:

  1. sudo apt-get install gnuplot</span>  
安装完了之后,用命令:gnuplot进入其界面。


2,简单绘图

用命令: >plot  sin(x)

就可以很轻松地画出sin(x)的图像,这一点很像MATLAB的plot的用法。也可以通过set 来修改图像的一些参数,程序如下:

  1. set title "Simple Funcrion Plot"  
  2. set xrange [-3 : 3]  
  3. set yrange [-1 : 1]  
  4. set xlabel  "theta"  
  5. set ylabel "sin(theta)"  
  6. set label "sin(0.0)" at 0.0 , 0.0  
  7. plot sin(x)  

运行结果如下:



3, 3-D画图 将数据图像保存到文件

  1. set title "A Simple Function to splot"    /*标题*/  
  2. set xrange [-4:4]        /*x轴的范围*/  
  3. set yrange [-4:4]        /*y轴的范围*/  
  4. set ylabel "Y-AXES"        /*X轴标记*/  
  5. set xlabel "X-AXES"        /*Y轴标记*/  
  6. set isosample 40        /*设置图像的栅格线密度,即作图的采样密度*/  
  7. set hidden                 /*隐线消除*/  
  8. set terminal png          /*terminal控制输出格式,文件的输出格式*/  
  9. set output "plot.png"        /*指定图像的输出名*/  
  10. splot  sin(x)*cos(y)         /*splot 3-D作图函数*/

4,多图模式

  1. /* 
  2. 多图模式,利用layout函数进行分块,类似于:subplot 
  3. */  
  4. set multiplot layout 1 ,2 rowsfirst title "Example Multiplot"  
  5. set title "Top"  
  6. set hidden  
  7. set isosample 40  
  8. splot [x=-4:4] [y=-4:4] sin(x)*cos(y)  
  9.   
  10. set title "Down"  
  11. set hidden   
  12. set isosample 10  
  13. set xrange [-3 : 3]  
  14. set yrange [-1 : 1]  
  15. set xlabel "X"  
  16. set ylabel "sin(X)"  
  17. plot sin(x)

相关内容