Search code examples
gnuplothistogrambinning

Histogram with custom bin sizes using gnuplot?


I know how to create a histogram (just use "with boxes") in gnuplot if my .dat file already has properly binned data. Is there a way to take a list of numbers and have gnuplot provide a histogram based on ranges and bin sizes the user provides?


Solution

  • yes, and its quick and simple though very hidden:

    binwidth=5
    bin(x,width)=width*floor(x/width)
    
    plot 'datafile' using (bin($1,binwidth)):(1.0) smooth freq with boxes

    check out help smooth freq to see why the above makes a histogram

    to deal with ranges just set the xrange variable.