I make a very simple test between my own routine to calculate histogram (written in IDL) and the one computed with 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'
To make the test very simple I generate a particular number of objects in each bin (the bin width is equal to 0.02). So that I now perfectly how many object there are in each bin.
Now I Compute the bin in IDL program so that it count the numbers inside the min and maximum value and in fact it compute them as I want. BUT when I try to use the hist
function of gnuplot I can be able to reproduce the (correct) result of my IDL histogram. I attach the randomIDL.dat in which You can found the numbers of object in every bin and the random.dat file in which you found ALL the objects (this is the file to pass to GNUplot hist
)
Here the different output:
Also if I shift the hist(x,width)
function I can be able to reproduce the correct IDL histogram.
I red the post: Histogram using gnuplot? but I can't be able to understand how to tell to GUNplot how to shift correctly the min and max of the bin inside which counts the elements.
The intervals for computing the counts are different. Yours are centered at 0, 0.02, 0.04, and so on. Gnuplot's are centered at 0.01, 0.03, 0.05, and so on. Change your bin function to this:
hist(x,width)=width*floor(x/width+0.5)