1

我正在使用以下命令绘制直方图:

n=3
max=0.5
min=-2.5
width=(max-min)/n
hist(x,width)=width*floor(x/width)+width/2.0
plot "< awk '{if (\$1<3.9 && \$1>3.8) {print \$0}}' /path_to_file/" u (hist(\$2,width)):(1.0) smooth freq w boxes lc rgb "black" lt 1 lw 0.5 notitle

这让我明白了:

直方图

显然,我根据数据文件猜测,gnuplot它自己决定选择区间 [1.0:0.0]-[0.0:-1.0]-[-1.0:-2.0] ,这使得 bin 以 [0.5:- 为中心0.5:-1.5]

我需要这些垃圾箱使用间隔 [0.5:-0.5]-[-0.5:-1.5]-[-1.5:-2.5] 这将使垃圾箱居中 [0.0:-1.0:-2.0]

我怎样才能做到这一点?

4

2 回答 2

0

我认为你想要的功能是

hist(x,width)     = width*(floor(x/width+0.5))

这是早期答案的等效但简化版本https://stackoverflow.com/a/13896530/834416

hist(x,width)     = width*floor((x + width/2)/width)

我遇到了同样的问题,并在https://stackoverflow.com/a/24923363/834416上发布了答案、示例代码和输出

于 2014-07-24T03:08:23.230 回答
0

直方图中的间隔由函数确定histhist函数将一系列数字缩小为单个值,因此 gnuplot 可以绘制以hist函数返回值为中心的条形图。

在您的原始帖子中,hist(x,width)=width*floor(x/width)+width/2. 因此,您将hist(x,width)=0.5得到width=10 <= x < 1。最终,您将得到一个以 为中心的条形图0.5

现在,如果要将间隔设置为 [-0.5:0.5]、[-0.5:-1.5] 等,您可能需要更改hist函数以使其0.0width=1和时返回-0.5 <= x < 0.5

width=1
hist(x,width)=width*floor((x + width/2)/width)
plot "< awk '{if (\$1<3.9 && \$1>3.8) {print \$0}}' /path_to_file/" u (hist(\$2,width)):(1.0) smooth freq w boxes lc rgb "black" lt 1 lw 0.5 notitleenter code here
于 2012-12-15T21:47:25.883 回答