歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

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)
Copyright © Linux教程網 All Rights Reserved