2011-07-03 39 views
24

我怎麼能做到這一點的gnuplot中:gnuplot的條件繪圖:劇情山坳:列B如果山坳ç== X

plot "test.csv" using 1:2 if value_in_column_3 == 80.0 

它應該只選擇那些行,其中列3 == 80.0,而忽略其他所有行(它不應該爲其他行繪製一個0,簡單地忽略它們)

在此先感謝。

+0

如何情節$ 3中只如果它不等於2美元? – SDsolar

回答

31

考慮下面的數據集(1.dat),

1 0.8 0 
2 0.6 0 
3 0.9 1 
4 1.1 0 
5 0.7 0 
6 0.6 1 

,我們僅希望在第三個等於零繪製前兩列。然後,你可以試試這個:

plot '1.dat' using 1:($3==0?$2:1/0) 

(感謝markjoe gnuplot的郵件列表上。)

+4

請注意,由於「1/0」是無效值,因此如果選擇繪製「線條」或「線條點」,則會導致問題。這是討論在http://stackoverflow.com/questions/11187691/gnuplot-conditional-plotting-2-15-2-1-0-with-lines – sdaau

15

情況下一個要有條件地繪製在另一列包含文本:

數據

1 0.8 a 
2 0.6 a 
3 0.9 a 
1 2.1 b 
2 1.7 b 
3 1.6 b 

代碼

set terminal postscript color 
set xrange [0:4] 
set yrange [0:3] 
plot "1.dat" using 1:(stringcolumn(3) eq "a"? $2:1/0) title "a" lc rgb "blue" ,\ 
    "" using 1:(stringcolumn(3) eq "b"? $2:1/0) title "b" lc rgb "red" 

命令

gnuplot <1.par> 1.ps 
5

如葉綠素上面說,在gnuplot的做到這一點的唯一方法是相當哈克:你必須使用的gnuplot的terniary:運營商生成您要過濾掉的點數值誤差你的數據集。

我在這裏可以偏置爲我對這個項目的作者,但你可能想看看Pyxplot http://www.pyxplot.org.uk(也是免費和開源的),由一組gnuplot的用戶誰是有點厭倦寫用這樣的hacky語法。

它的語法與gnuplot非常相似,但帶有擴展名。對於您想要的,您可以在繪圖命令中指定「選擇標準」,並且只有在測試爲真時才包含點。有關更多信息,請參閱http://pyxplot.org.uk/current/doc/html/sec-select_modifier.html

+0

而不是使用1/0,你可以使用NaN(不一個數字),它具有完全相同的效果,但看起來更美觀。 –

4

另一個黑客是使用像awk shell命令:

plot "< awk '$3==80.0 { print $1, $2 }' test.csv" using 1:2 
2

如果要調用的腳本,使用column(2)代替$2

plot "1.dat" using 1:(stringcolumn(3) eq "a"? column(2):1/0) title "a" lc rgb "blue" ,\ 
    "" using 1:(stringcolumn(3) eq "b"? column(2):1/0) title "b" lc rgb "red"