在Gnuplot直方图中居中存储箱

在Gnuplot直方图中居中存储箱,gnuplot,histogram,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的箱子的右边缘高于零。我想让垃圾箱中心定位。也就是说,我希望每个箱子的中

在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的箱子的右边缘高于零。我想让垃圾箱中心定位。也就是说,我希望每个箱子的中心在对应的x值之上。我尝试过处理binx,width的参数,但没有成功。有什么建议吗

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)
给予


请注意,[-0.25,0.25]中的值映射到位置0处的箱子,[0.25,0.75]中的值映射到位置0.5处的箱子,依此类推。

您定义了自己的roundx吗?我猜roundx=x-floorx<0.5?floorx:ceilx?你是对的;我忘了圆函数。我编辑了我的答案,添加了roundx=floorx+0.5。对不起!