我在自己计算直方图(用 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,以便计算最小值和最大值内的数字,实际上它可以根据需要计算它们。但是当我尝试使用hist
gnuplot 的功能时,我可以重现 IDL 直方图的(正确)结果。我附上了randomIDL.dat,您可以在其中找到每个 bin 中的对象数量,以及您在其中找到所有对象的random.dathist
文件(这是传递给 GNUplot 的文件)
这里不同的输出:
此外,如果我改变hist(x,width)
函数,我可以重现正确的 IDL 直方图。
我把帖子发红了:Histogram using gnuplot? 但我无法理解如何告诉 GUNplot 如何正确移动计数元素的 bin 的最小值和最大值。