【问题标题】:Gnuplot histogram with boxes different results带有不同结果的 Gnuplot 直方图
【发布时间】:2014-08-04 23:37:35
【问题描述】:

我在我自己计算直方图的例程(用 IDL 编写)和使用 gnuplot 计算的例程之间做了一个非常简单的测试。

clear
reset

width=0.02
set terminal pngcairo size 800,500 enhanced font 'Verdana,14'
set output "GNUvsMY.png"
set boxwidth width
set style fill transparent solid 0.5 border #fillstyle
set grid
set ytics 0.,5,40
set xrange [-0.09:0.09]
set yrange [0:40]
set xlabel "x"
set ylabel "Frequency [N]"
##########
hist(x,width)=width*floor(x/width)+width/2.0
#########
plot "randomIDL.dat" u 2:1 w boxes lc rgb "blue" title 'test3 my hist',\
     "random.dat" u (hist($1,width)):(1.0) smooth freq w boxes lc rgb "red" title 'test3 GNU shift'

为了使测试非常简单,我在每个 bin 中生成特定数量的对象(bin 宽度等于 0.02)。所以我现在完美地知道每个箱子里有多少个物体。

现在我在 IDL 程序中计算 bin,以便计算最小值和最大值内的数字,实际上它可以根据需要计算它们。但是当我尝试使用 gnuplot 的 hist 函数时,我可以重现 IDL 直方图的(正确)结果。我附上了randomIDL.dat,您可以在其中找到每个垃圾箱中的对象数量,以及您在其中找到所有对象的random.dat文件(这是传递给GNUplot hist的文件)

这里是不同的输出:

此外,如果我移动 hist(x,width) 函数,我可以重现正确的 IDL 直方图。

我把帖子发红了:Histogram using gnuplot?,但我无法理解如何告诉 GUNplot 如何正确移动计数元素的 bin 的最小值和最大值。

【问题讨论】:

    标签: plot gnuplot histogram binning


    【解决方案1】:

    计算计数的间隔不同。您的以 0、0.02、0.04 等为中心。 Gnuplot 以 0.01、0.03、0.05 等为中心。将您的 bin 函数更改为:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-01
      相关资源
      最近更新 更多