# method "0"
bw = 5 # substitute what you want
bin(x,width)=width*floor(x/width)
plot 'data' using (bin($1,bw)):(1.0) smooth freq with boxes
# Making histograms within gnuplot -
# cunning trick using gnuplot's "smooth frequency"
#
# method 1:
#
# to make a histogram with vertical axis equal to the count
# in a bin:
#
bin_width = 0.3; ## edit this
bin_number(x) = floor(x/bin_width)
rounded(x) = bin_width * ( bin_number(x) + 0.5 )
UNITY = 1
## column number of data to be histogrammed is here assumed to be 1
## - change $1 to another column if desired
plot 'dat' u (rounded($1)):(UNITY) t 'data' smooth frequency w histeps
pause -1 'ready'
#
# method 2:
#
# to make a histogram with *area* of a bin equal to the count
# in a bin, so the area under the curve is the number of data:
#
bin_width = 0.3
bin_number(x) = floor(x/bin_width)
rounded(x) = bin_width * ( bin_number(x) + 0.5 )
UNITY = 1
plot 'dat' u (rounded($1)):(UNITY/bin_width) t 'data' smooth frequency w histeps
pause -1 'ready'
#
# method 3, second example, which illustrates why you might sometimes
# prefer method 2 to method 1 (namely, to make it possible to
# superpose two histograms of the same data):
#
bin_width = 0.3
bin_number(x) = floor(x/bin_width)
rounded(x) = bin_width * ( bin_number(x) + 0.5 )
bin_width2 = 1.0
bin_number2(x) = floor(x/bin_width2)
rounded2(x) = bin_width2 * ( bin_number2(x) + 0.5 )
UNITY = 1
plot 'dat' u (rounded($1)):(UNITY/bin_width) t 'width 0.3' smooth frequency w histeps,\
'dat' u (rounded2($1)):(UNITY/bin_width2) t 'width 1' smooth frequency w histeps 3
by David MacKay, THANKS!