Gnuplot直方图中的中心箱

时间:2017-09-24 23:49:50

标签: gnuplot histogram

在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 个答案:

答案 0 :(得分: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.25,0.25]中的值映射到位置0处的bin,[0.25,0.75]中的值映射到位置0.5处的bin,依此类推。