2015-11-13 34 views
0

我有一個像下面的數據文件:是否可以在gnuplot中每十行繪製一行?

#X1 y1 x2 y2 Number 
123 567 798 900 1 
788 900 87 89 2 
.... 

,我使用下面的命令

plot '~/Desktop/pointcolor.txt' using 1:2:($3-$1):($4-$2):5 with vectors palette nohead notitle 

這裏是結果得出我的圖表。

Result Graph

正如你可以在上面的圖片查看,結果是壓縮的,所以我想每個具有在數據文件中相同數量的十行畫一條線。

EDIT1:

我嘗試@ewcz解決方案,如下:

stat="0 0 0 0 0 0 0" # How should I define array as [gnuplot][2] didn't support it? 
plot "< awk '{if(((stat[$5]++)%10==0)) print}'~/Desktop/pointt.txt" using 1:2:($3-$1):($4-$2):5 with vectors palette nohead notitle 

,但我得到這個錯誤:

gnuplot> load "gnuplot.cmd" 
awk: line 1: syntax error at or near 

gnuplot> plot "< awk '{if(((stat[$5]++)%10==0)) print}'~/Desktop/pointcolor.txt" using 1:2:($3-$1):($4-$2):5 with vectors palette nohead notitle 
                                    ^
     "gnuplot.cmd", line 6: warning: Skipping data file with no valid points 

gnuplot> plot "< awk '{if(((stat[$5]++)%10==0)) print}'~/Desktop/pointcolor.txt" using 1:2:($3-$1):($4-$2):5 with vectors palette nohead notitle 
                                      ^
     "gnuplot.cmd", line 6: x range is invalid 

EDIT2:

的解決方案:

plot "< awk '{if((stat[$5]++)%10==0) print}' ~/Desktop/pointt.txt" using 1:2:($3-$1):($4-$2):5 with vectors palette nohead notitle 
+0

這些鏈接使用'every'選項根據行號來畫線,在我的情況下如何使用這個選項? – user3806649

+0

'stat'數組在內部調用'(g)awk',不需要'stat =「0 0 0 0 0 0」'行。另外,'〜'字符前面應該有一個空格,以便'awk'可以區分用撇號括起來的命令和正在處理的文件'〜/ Desktop/pointcolor.txt' – ewcz

+0

我仍然得到一個錯誤:( – user3806649

回答

2

爲了達到這個目的,我們必須使用(很可能)對輸入進行某種預處理。幸運的是,Gnuplot允許以直接的方式繪製命令的結果。

plot "< gawk '{if((stat[$5]++)%10==0) print;}' ~/Desktop/pointcolor.txt" ... 

這裏,行(基於第五列)的ID存儲在陣列stat:在你的情況下,作爲一個可以修改的情節命令。如果這個id可以被10整除,則該行被打印並因此被繪製(即,其他輸入行被丟棄)。

+0

我得到一個錯誤時嘗試它,我有更新的問題取決於它 – user3806649

相關問題