Histograms
A histogram is similar to a bar chart, but both axes represent numerical values. Histograms are generally used to display the distribution of values for a numeric variable. You can create a histogram using the Plot.Create.Histogram
method:
This method has two overloads: the first overload (used in the example above) accepts an IReadOnlyList<double>
as a first parameter and creates a histogram showing the distribution of the values in the input array. This has a number of optional parameters that can be used to determine the appearance of some elements of the plot. Many of these are in common with other kinds of plots and are described in the page about scatter plots; here are the ones specific to this method:
bool vertical
: if this istrue
(the default), the base of the bars lies on theX
axis and the bars go from bottom to top. If this isfalse
, the base of the bars lies on theY
axis and the bars go from left to right.double margin
: this determines the amount of space between consecutive bars.int binCount
: this parameter determines the number of bins (bars) in the histogram. If this is ≤ 1 (the default is-1
), the number of bins to use is determined automatically using the Freedman-Diaconis rule.double underflow
: values in the input array that are smaller than this value are excluded from the histogram and included in an underflow bar. The default is $-\infty$, i.e., no underflow bar is drawn.double overflow
: values in the input array that are larger than this value are excluded from the histogram and included in an overflow bar. The default is $+\infty$, i.e., no overflow bar is drawn.PlotElementPresentationAttributes dataPresentationAttributes
: this determines the appearance (stroke, fill, etc) of the bars.
The second overload accepts a first parameter of type IReadOnlyList<IReadOnlyList<double>>
which, instead, should contain data that have already been pre-binned. Each element of this array should be an array containing two elements, the first being the X coordinate of the centre of a bar, and the second being the height of the bar. This makes it possible to create histograms with unequal bin widths, but for this you will have to bin the data yourself. As a consequence, this method does not have binCount
, underflow
or overflow
parameters, while the other parameters are the same as for the other overload of the Histogram
method.