【问题标题】:gnuplot - Select bin center in histogramgnuplot - 在直方图中选择 bin 中心
【发布时间】:2012-10-01 15:32:12
【问题描述】:

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

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] 来生成垃圾箱以 [0.5:-0.5:-1.5] 为中心

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

我怎样才能做到这一点?

【问题讨论】:

  • 您只想更改 x 轴上的标签吗?
  • 嗨@mgilson,不,我希望gnuplot 实际使用我写的那些间隔,而不是它自己决定使用的那些间隔。如何告诉gnuplot 从哪个位置开始计数以生成具有我设置的宽度的间隔?
  • 所以你想转换x -&gt; x-0.5?试试:hist(x,width)=width*floor((x-0.5)/width)+width/2.0
  • 嗯,我不完全确定它在做什么,但这不是我需要的。我需要gnuplot 将垃圾箱围绕 0.0、-1.0 和 -2.0(宽度为“1”)居中,而不是默认情况下它们如何居中,即 0.5、-0.5 和 -1.5。我希望gnuplot 计算每个区间 [0.5:-0.5]-[-0.5:-1.5]-[-1.5:-2.5] 内的对象数量,并且 not 它在做什么正确现在以 [1.0:0.0]-[0.0:-1.0]-[-1.0:-2.0] 的间隔计算它们。

标签: gnuplot histogram


【解决方案1】:

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

在您的原始帖子中,hist(x,width)=width*floor(x/width)+width/2。因此,对于width=10 &lt;= x &lt; 1,您将获得hist(x,width)=0.5。最终,您将获得以0.5 为中心的条形图。

现在,如果您想将间隔设置为 [-0.5:0.5]、[-0.5:-1.5] 等,您可能需要更改您的 hist 函数,以便它在以下情况下返回 0.0 width=1-0.5 &lt;= x &lt; 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

【讨论】:

    【解决方案2】:

    我认为你想要的函数是

    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发布了答案和示例代码和输出

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-01
      • 2016-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多