2017-09-24 91 views
0

在gnuplot的定心箱,你可以創建一個像在gnuplot的直方圖

binwidth=#whatever# 
set boxwidth binwidth 
bin(x,width)=width*floor(x/width)+binwidth/2.0 
plot "gaussian.data" u (bin($1,binwidth)):(1.0/10000) smooth freq w boxes 

目前的柱狀圖,我似乎箱的右側邊緣爲中心。也就是說,對應於x = 0的bin具有大於零的右邊緣。我希望以垃圾箱爲中心。也就是說,我希望每個bin的中心位於相應的x值之上。我已經嘗試了bin(x,width)的參數,但一直沒有成功。有什麼建議麼?

回答

1
bin(x,width) = width*round(x/width) 

應該訣竅。你可以簡單的可視化的合併是如何工作的:

binwidth = 0.5 
round(x) = floor(x+0.5) 
bin(x,width) = width*round(x/width) 
set xrange [-2:2] 
set xlabel "x" 
set ylabel "bin position" 
set grid 
plot bin(x,binwidth) 

enter image description here

注意,在位置0值[-0.25,0.25]被映射到垃圾桶,在值[0.25, 0.75]被映射到位置0.5處的箱,等等。

+0

你有沒有定義你自己的'round(x)'? – Ptheguy

+0

我猜'round(x)= x-floor(x)<0.5?地板(X):小區(X)'? – Ptheguy

+0

你是對的;我忘了「圓」功能。我編輯了我的答案,以添加'round(x)= floor(x + 0.5)'。對於那個很抱歉! – user8153