Contents Previous Next Subchapters

Plotting Histograms
Syntax ghist(y
ghist(
ynb
ghist(
ynbcolor
ghist(
ynbcolorcindex)
See Also gstair , gbar

Description
Plots a histogram with optional specification of the number of bins, the color, and grouping of elements by color. The histogram is scaled so that the height of each bin corresponds to the sample density for that bin. The size of the bins are adjusted to have the same number of samples in each bin with the exception that bins in the center may have one less sample than bins at the ends. If all of the entries in a bin have the same value, the entries are plotted as one cross for each entry above the value.

The real or double-precision column vector y contains the data values that are being plotted. If the argument nb is present, the row dimension of y must be greater than or equal to nb. Otherwise, the row dimension of y must be greater than or equal to ten.

If integer scalar nb is present, it specifies the number of bins in the histogram. Otherwise there are ten bins in the histogram.

If the character matrix color is present, it specifies the plotting colors for the histogram. Each row of color must contain a valid O-Matrix plotting color; i.e., "black", "maroon", "green", "olive", "navy", "purple", "teal", "gray", "silver", "red", "lime", "yellow", "blue", "fuschia", or "aqua".

If the integer column vector cindex is present, it specifies which elements of y correspond to which colors in the histogram. The element y(i) corresponds to the color color.row(cindex(i)). Each element of cindex must have a value between one and the row dimension of color.

Example
If you enter
     y     = rand(499, 1)
     nb    = 20
     ghist(y, nb)
O-Matrix will plot a histogram of 499 samples that are uniformly distributed between zero and one.

The following program plots a similar histogram in which the even indices correspond to "green" and the odd indices correspond to "red".

clear
#
y      = rand(499, 1)
nb     = 20
color  = {"red", "green"}
even   = mod(seq(499), 2) == 0
odd    = not even
cindex = odd % fill(1, 499, 1) + even % fill(2, 499, 1)
ghist(y, nb, color, cindex)