天天看點

gnuplot繪圖學習

Gnuplot 是一種免費分發的繪圖工具,可以移植到各種主流平台,也可以使用程式設計語言産生的資料進行繪圖

1.配置gnuplot

為了能在指令視窗運作gnuplot,需要将gnuplot.exe路徑添加到windows路徑中(Windows10為例),将gnuplot安裝好了以後,記住它的安裝路徑

方法為:

控制台->進階系統設定->環境變量->系統變量->Path

gnuplot繪圖學習

指令視窗顯示:

gnuplot繪圖學習

2.gnuplot繪圖常識

gnuplot繪圖程式中對線型(linetype)、點型(pointtype)、線條寬度(linewidth)、點大小(pointsize)、圖樣(style)都有相應的設定值,具體設定如下:

(1)線型(linetype )。在此類型中主要設定線條的顔色,具體對應如下:

n 1 2 3 4 5 6
linetype black red green blue pink 淺藍 yellow

(2)點型(pointtype)。此類型用于設定點得形狀,可分為14中,具體對應如下:

n 1 2 3 4 5 6 7 8 9 10 11 12 13
pointtype + × *

(3)w lp

即 with linepoint ,把資料點描出來,并且将資料點連線。with 後的屬性參數有多個選擇,對應不同的作圖方式(style)。在指令視窗輸入 hplp with 或者 help style就可以查到可供選擇的 style 參數。常用的作圖方式參數及對應含義如下表所示:

style參數 簡寫 對應含義
line l 将相鄰點連線
point p 将每一點用一符号标記
linepoint lp 将每一點用一符号标記,并将相鄰點連線
impulses i 将每一點畫一垂直線至x軸
steps st 用垂直線及水準線各一條來連接配接兩點,形成台階狀圖形
boxes boxes 以x坐标為中心做柱狀圖
errorbars e 對每一點坐标值(x,y),畫一由(x,ylow) 至(x,yhigh) 的線段。并線上段兩端做上 tic mark
boxerrorbars boxerrorbars 結合errorbars與boxes兩者功能

(4)lt 1

即 linetype 1 ,規定了連線的類型,-1對應黑虛線,0對應黑虛線,大于0的整數對應不同顔色的實線。1為紫色,2為綠色,3為藍色,4為橙色、5為黃色、6為深藍色、7為紅色、8為黑色,大于8的數字對應的顔色與其對8的餘數對應的顔色相同。

(5)lw 2

即 linewidth 2 ,規定了線的寬度,數字越大,線越寬。

(6)pt 4

即 pointtype 4,規定了标記點的類型

2.gnuplot繪圖顯示

(1)繪圖1

gnuplot> set title "study gnuplot"  //建立标題
gnuplot> set xlabel "Angle"  //x軸标題
gnuplot> set ylabel "sin(angle)"//y軸标題
gnuplot> set key top left//關鍵字位置
gnuplot> set key box
gnuplot> plot [-pi:pi] sin(x) title "sinone" with linespoints pointtype 5,cos(x) t 'cosone' w boxes lt 4// 繪圖範圍、點的類型以及線條連線
gnuplot>
           
gnuplot繪圖學習

效果:

gnuplot繪圖學習

(2)繪圖2

gnuplot> set title "study gnuplot"
gnuplot> set xlabel "Angle"
gnuplot> set ylabel "sin(angle)"
gnuplot> set xrange [-pi:pi]
gnuplot> set size 1,1
gnuplot> set origin 0,0
gnuplot> set multiplot     //建立多圖像
multiplot> set size 0.5,0.5
multiplot> set origin 0,0.5
multiplot> plot sin(x)
multiplot> set size 0.5,0.5
multiplot> set origin0,0
               ^
           unrecognized option - see 'help set'.

multiplot> set origin 0,0
multiplot> plot 1/sin(x)
multiplot> set size 0.5,0.5
multiplot> set origin 0.5,0.5
multiplot> plot cos(x)
multiplot> set size 0.5,0.5
multiplot> set origin 0.5,0
multiplot> plot 1/cos(x)
multiplot>
           
gnuplot繪圖學習

效果:

gnuplot繪圖學習

繼續閱讀