【问题标题】:Centering bins in Gnuplot Histogram在 Gnuplot 直方图中居中 bin
【发布时间】:2017-09-24 23:49:50
【问题描述】:

在 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) 的参数,但没有成功。有什么建议吗?

【问题讨论】:

    标签: gnuplot histogram


    【解决方案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)
    

    给予

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

    【讨论】:

    • 你定义了自己的round(x)吗?
    • 我猜round(x)=x-floor(x) < 0.5 ? floor(x):ceil(x)?
    • 你是对的;我忘记了“圆形”功能。我编辑了答案以添加round(x) = floor(x+0.5)。很抱歉!
    猜你喜欢
    • 1970-01-01
    • 2016-02-07
    • 1970-01-01
    • 1970-01-01
    • 2013-07-28
    • 1970-01-01
    • 1970-01-01
    • 2017-08-25
    • 2016-05-27
    相关资源
    最近更新 更多