MATLAB Function Reference
  Go to function:
    Search    Help Desk 
hist    Examples   See Also

Histogram plot

Syntax

Description

A histogram shows the distribution of data values.

n = hist(Y) draws a histogram of the elements in Y, binning the data into ten equally spaced containers and returns the number of elements in each container. If Y is a matrix, hist works down the columns. hist distributes the bins along the x-axis between the minimum and maximum values of Y.

n = hist(Y,x) draws a histogram using n bins, where n is length(x). x also specifies the locations on the x-axis where hist places the bins. For example, if x is a 5-element vector, hist distributes the elements of Y into five bins centered on the x-axis at the elements in x.

n = hist(Y,nbins) draws a histogram with no more bins than nbins.

[n,xout] = hist(...) returns vectors n and xout containing the frequency counts and the bin locations. This syntax does not generate a plot. This is useful when you need more control over the appearance of a graph, for example, to combine a histogram into a more elaborate plot. You can use bar(xout,n) to plot the histogram.

Remarks

All elements in vector Y or in one column of matrix Y are grouped according to their numeric range. Each group is shown as one bin.

The histogram's x-axis reflects the range of values in Y. The histogram's y-axis shows the number of elements that fall within the groups; therefore, the y-axis ranges from 0 to the greatest number of elements deposited in any bin.

The histogram is created with a Patch graphics object. If you want to change the color of the graph, you can set Patch properties. See the "Example" section for more information. By default, the graph color is controlled by the current colormap, which maps the bin color to the first color in the colormap.

Examples

Generate a bell-curve histogram from Gaussian data:

Change the color of the graph so that the bins are red and the edges of the bins are white:

See Also

bar,ColorSpec, patch, stairs



[ Previous | Help Desk | Next ]