The histogram command takes data from a file and bins it, producing a function that represents the frequency distribution of the supplied data. A histogram is defined as a function consisting of discrete intervals, the area under each of which is equal to the number of points binned in that interval. For example:
histogram f() 'input.dat'
would bin the points in the first column of the file input.dat into bins of unit width and produce a function , the value of which at any given point was equal to the number of items in the bin at that point.
Modifiers can be supplied to the histogram command command to control the bins that it uses. The binwidth modifier sets the width of the bins used and the binorigin modifier their origin. For example:
histogram wabbitcount() 'rabits.dat' binorigin 0.5 binwidth 2
bins the rabbit data into bins between and
,
and
, etc. Alternatively the bins modifier allows an arbitrary set of bins to be specified. For example the command:
histogram g() 'input.dat' bins (1, 2, 4)
would bin the points in the first column of the file input.dat into two bins, and
.
A range can be supplied immediately following the command, using the same syntax as in the plot and fit commands; only points that fall in that range will then be binned. In the same way as for the plot command, the index, every, using and select modifiers can also be used to bin different portions of a datafile.
Note that, although a histogram is similar to a bar chart, they are subtly different. A bar chart has the height of the bar equal to the number of points that it represents; for a histogram the area of the bar is equal to the number of points. To produce a bar chart use the histogram command and then multiply by the bin width when plotting.
If the function produced by the histogram command is plotted using the boxes plot style, box boundaries will be drawn to coincide with the bins into which the data were sorted.