GNU/Linux提供了進行數據可視化的很多開源解決方案。 這些解決方案不僅能將數據轉換成示意圖,圖表和特定的圖像,還能對數據進行過濾和精簡以使其更加有用。Gnuplot是最古老的可視化程序之一,也是最好用的。今天在《GNU/LINUX環境編程》中看到了,學習了一下,以下就做個學習筆記吧。
1,安裝Gnuplot
如果你的電腦裡沒有Gnuplot , 可以用以下的命令安裝:
- sudo apt-get install gnuplot</span>
安裝完了之後,用命令:gnuplot進入其界面。
2,簡單繪圖
用命令: >plot sin(x)
就可以很輕松地畫出sin(x)的圖像,這一點很像MATLAB的plot的用法。也可以通過set 來修改圖像的一些參數,程序如下:
- set title "Simple Funcrion Plot"
- set xrange [-3 : 3]
- set yrange [-1 : 1]
- set xlabel "theta"
- set ylabel "sin(theta)"
- set label "sin(0.0)" at 0.0 , 0.0
- plot sin(x)
運行結果如下:
3, 3-D畫圖 將數據圖像保存到文件
- set title "A Simple Function to splot" /*標題*/
- set xrange [-4:4] /*x軸的范圍*/
- set yrange [-4:4] /*y軸的范圍*/
- set ylabel "Y-AXES" /*X軸標記*/
- set xlabel "X-AXES" /*Y軸標記*/
- set isosample 40 /*設置圖像的柵格線密度,即作圖的采樣密度*/
- set hidden /*隱線消除*/
- set terminal png /*terminal控制輸出格式,文件的輸出格式*/
- set output "plot.png" /*指定圖像的輸出名*/
- splot sin(x)*cos(y) /*splot 3-D作圖函數*/
4,多圖模式
- /*
- 多圖模式,利用layout函數進行分塊,類似於:subplot
- */
- set multiplot layout 1 ,2 rowsfirst title "Example Multiplot"
- set title "Top"
- set hidden
- set isosample 40
- splot [x=-4:4] [y=-4:4] sin(x)*cos(y)
-
- set title "Down"
- set hidden
- set isosample 10
- set xrange [-3 : 3]
- set yrange [-1 : 1]
- set xlabel "X"
- set ylabel "sin(X)"
- plot sin(x)