2015-10-21 48 views
2

我嘗試繪圖用不同大小的點文件,如下圖:gnuplot的變量的pointsize

N = 3 

symbol(N) = strcol(N) eq "3" ? 3 : (strcol(N) eq "2" ? 2 : (strcol(N) eq "1" ? 1 : 0) ) 

set xrange [0:6] 
plot 'data.dat' using 2:1:(symbol(N)*1) with points pt 7 ps var 

其實這是正確的,如果第三列是由整數(即:1,2,5),但如果文件格式爲:

#1st cl 2nd cl 3rd cl 

23.  0.  4.21 
34.  0.  1.2 
56.  0.  1.92 

我無法繪製任何東西。是因爲我必須改變symbol(N)這一行嗎?

感謝所有。

+0

爲什麼不用'plot'data.dat'使用2:1:3點pt 7 ps var'?如果您檢查是否相等,並且不提供等於「1」,「2」或「3」的數據,則不會顯示任何內容...... – vaettchen

回答

1

不知道爲什麼你正在服用這種複雜的方法,但我猜你想要達到的目標,這應該是接近:

數據集

#1st cl 2nd cl 3rd cl 
23.  0.  1.5 
34.  0.  2.5 
56.  0.  3.5 

gnuplot的命令:

plot[ -1:7 ] 'data.dat' using 2:1:(column(3) > 3 ? 3 : (column(3) < 2 ? 1 : 2)) with points pt 7 ps var 

圖:

enter image description here

2

您的代碼不與非整數的工作,因爲symbol(N)返回0時N不爲1,2,或3:

gnuplot> symbol(N) = (N==3 ? 3 : (N==2 ? 2 : (N==1 ? 1 : 0))) 
gnuplot> print symbol(1.0), symbol(3.0), symbol(4.21), symbol(1.2) 
1 3 0 0 

這些都是這個函數的一些變化,可以幫助你:

:我定義 symbol(N)strcol(N),這樣你就可以調用這個函數作爲
symbol(N) = (floor(N) == N ? N : 0.5)  # return N if N is an integer; return 0.5 otherwise 
symbol(N) = floor(N)      # return largest integer not greater than N 
symbol(N) = ceil(N)      # return smallest integer not less than N 
symbol(N) = N        # just return N, doh' 

公告