2015-10-05 54 views
1

我繪製在散點圖CSV文件,使用下面的命令與gnuplot的連接線:如何用閉合線做GNUPlot散點圖?

set style line 1 lc rgb '#0060ad' lt 1 lw 1 pt 7 pi -1 ps 1 
set pointintervalbox 1.25 

plot "values.csv" using 1:2 with lp ls 1 

它看起來很棒,但我得到的是一個打開的多邊形,因爲gnuplot的不畫線連接第一點和最後一個。

如何獲得gnuplot連接第一個和最後一個點,以便獲得封閉的多邊形?

+1

請參閱[此答案](http://stackoverflow.com/a/32793123/2174266),[和此](http://stackoverflow.com/a/29018902/2174266)在SO上。 – vagoberto

回答

1

最簡單的方法是通過修改數據文件在評論中提出。但是,如果您想要看起來可以執行一些awk即時預處理,以將第一個數據點追加到文件末尾。

考慮以下數據文件:

# Some comment for the sake of generality 
0 0 
1 1 
2 1 
2 0 

它看起來像這樣沒有任何處理(例如,plot "data" w l):

enter image description here

我們刪除註釋和第一行添加到結束的文件:

datafile = "< grep -v '#' data | awk '{if(NR==1) {i += 1; temp = $0; print \ 
$0;} else {i += 1; print $0;}} END {print temp}'" 

plot datafile w l 

enter image description here