gnuplot畫圖技巧總結

來源:互聯網
上載者:User

標籤:gnuplot   畫圖軟體   點線   技巧總結   

---------------------------------------------------------------------------------------------------------

本文歡迎轉載,轉載請附上連結http://blog.csdn.net/iemyxie/article/details/41548583

---------------------------------------------------------------------------------------------------------

最近用gnuplot畫了不少圖,關鍵字神馬的每次用到都要重新去查使用文檔,簡直神煩。所以乾脆將常用的技巧總結成文,以便日後查閱。


一、gnuplot簡介

可能我說了半天還有人不造gnuplot是個啥東西呢。gnuplot,輕量級畫圖神器。放上維基百科的解釋:gnuplot是一套跨平台的數學繪圖自由軟體。使用互動式介面,可以繪製數學函數圖形,也可以從純文字檔讀入簡單格式的座標資料,繪製統計圖表等等。它不是統計軟體,也不是數學軟體,它純粹只是一套函數/資料繪圖軟體。它可以產生PNG,SVG,PS,HPGL,……等等開放的圖形檔案格式的輸出,供文書處理/簡報/試算表/……等等軟體匯入。
功能:
繪畫二維或三維的映像
繪畫數學函數
從其他文檔讀入資料,繪畫統計圖表
被外部程式(如GNU Octave)調用

點擊下載gnuplot

二、畫點

先放一張博主初次接觸gnuplot畫的第一張圖。


附上部分代碼:

set term post eps color enh solid //固定格式set term pdfcairo lw 2 font 'Times_New_Roman,8'datafile='AfterP-H-kmeans++-k=6.data'set output 'AfterP-H-kmeans++-k=6.pdf'set title 'AfterP-H-kmeans++-k=6'
set multiplot //允許重複畫set key outside vertical //將標識置於圖外並保持垂直排列plot datafile using 7:1 title 'cluster0' with points lc rgb 'pink' 

a。

set :所有gnuplot設定均以set開頭
? term :即terminal,終端,指示圖片輸入輸出的格式。後面可以跟post eps,png,jpg等
? color :可以輸出彩色圖片和曲線
? enh :enhance,加強,可以輸入各種符號,如希臘字母等。
? solid:可使用實體線。
? datafile=“XXX.data” 資料檔案,檔案可以沒有尾碼,或txt,或data都可以。
? set output “XXX.jpg”輸出名為XXX.jpg的圖片?

?using後的7:1意思是使用資料檔案的第7列作為x軸,第1列作為y軸。注意x軸的值在前。

?“with points”即為畫點。

b。

關於key的置放位置,可以根據不同需求進行調整。

官方手冊上解釋如下:

set key {on|off} {default}
{{inside | outside} | {lmargin | rmargin | tmargin | bmargin}
| {at <position>}}
{left | right | center} {top | bottom | center}
{vertical | horizontal} {Left | Right}
{{no}opaque}
{{no}reverse} {{no}invert}
{samplen <sample_length>} {spacing <vertical_spacing>}
{width <width_increment>}
{height <height_increment>}
{{no}autotitle {columnheader}}
{title "<text>"} {{no}enhanced}
{font "<face>,<size>"} {textcolor <colorspec>}
{{no}box { {linestyle | ls <line_style>}
| {linetype | lt <line_type>}
{linewidth | lw <line_width>}}}
{maxcols {<max no. of columns> | auto}}
{maxrows {<max no. of rows> | auto}}
unset key
show key

記住一些常用的就可以了:vertical:豎直排列;horizontal:水平排列;right top:右上方;left top:左上方;outside:畫外放置;inside:畫內放置等。

c。
如何運行?可以將代碼儲存為“XXX.gnu”,在命令列中輸入:gnuplot XXX.gnu

或者儲存為“XXX.plt”這樣直接雙擊此文字文件即可得到結果,當然你的代碼必須是正確的。。否則。你的圖片大小會是0k。。

推薦第二種方法,比較方便。

二、畫線

a。單條線

照例,先放一張自己用gnuplot畫的圖


很簡單,一看代碼你就明白了。

set term post eps color enh solidset term pdfcairo lw 2 font 'Times_New_Roman,8'datafile='realDuration'set output 'realDuration-w1t1.pdf'set xlabel 'Time(ms)' //設定橫軸名稱set ylabel 'Duration(ms)' //設定縱軸名稱set grid //在圖中顯示網格plot datafile using 6:4 notitle with lines set output
b。畫多條線及平滑處理

平滑選項指定如何使資料之間的連線平滑。為了使資料製圖美觀和合理, 根據資料繪製的曲線有不同的平滑演算法。 
smooth {unique | frequency | cumulative | cnormal | kdensity| csplines | acsplines | bezier | sbezier}

autoscale 選項開啟,將使得平滑曲線總體在圖片邊界內。
autoscale 沒有開啟, 並且平滑選項為 acspine 和 cspline, 曲線採樣將穿過輸入資料的 x 地區。
Acsplines 自然樣條平滑。資料局部關於 x 單調, 曲線是分段函數。由係數符合輸入權重的, 三次多項式構造。
權重由第三輸入列表示。
Plot ‘data-file‘ using 1:2:(1.0) smooth acsplines
輸入權重的數量級將定性的影響曲線的分段數目。如果某個權重較大, 那麼它所在點對曲線影響越大。
曲線逼近串連各個點的 3 次自然樣條曲線。如果權重較小, 曲線由數個小片段組成, 總體上是平滑的。
極限情況是單個片段由加權線性最小二乘法產生, 逼近所有資料。資料誤差可用作平滑權重。

例子:(以下兩張圖片來自@Ivan)

命令:
plot "price.dat" using 1:2 with linespoints,"" using 1:2 title "bezier" smooth bezier,"" using 1:2 title "csplines" smooth csplines


plot [1975:1995][40:160] "price.dat" using 1:2 with points title "price.dat", "" u 1:2:(1) smooth acsplines title "1", "" using 1:2:(1/50.) smooth acsplines title "1/50", "" using 1:2:(50) smooth acsplines  title "50", "" using 1:2:(1/10000.) smooth acsplines title "1/10000"


畫多條線的方法也很簡單:如上所示的,plot "xxx","xxx2",“xxx3"即可

三、線和點的種類


emf格式下,gnuplot有十五種顏色lt 1 至 lt 15。lt 16也為紅色,但線形變為虛線。


emf格式下的前30種點、線


---------------------------------------------------------------------------------------------------------

本文歡迎轉載,轉載請附上連結http://blog.csdn.net/iemyxie/article/details/41548583

---------------------------------------------------------------------------------------------------------

gnuplot畫圖技巧總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.