Note: This page has been translated by MathWorks. Please click here

To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

Histogram plot

Histograms are a type of bar plot for numeric data that group the data into
bins. After you create a `Histogram`

object, you can modify aspects of
the histogram by changing its property values. This is particularly useful for quickly
modifying the properties of the bins or changing the display.

`histogram(X)`

`histogram(X,nbins)`

`histogram(X,edges)`

`histogram('BinEdges',edges,'BinCounts',counts)`

`histogram(C)`

`histogram(C,Categories)`

`histogram('Categories',Categories,'BinCounts',counts)`

`histogram(___,Name,Value)`

`histogram(ax,___)`

`h = histogram(___)`

`histogram(`

creates a histogram
plot of `X`

)`X`

. The `histogram`

function uses
an automatic binning algorithm that returns bins with a uniform width,
chosen to cover the range of elements in `X`

and reveal the
underlying shape of the distribution. `histogram`

displays the bins as rectangles such that the height of each rectangle
indicates the number of elements in the bin.

`histogram(`

, where
`C`

)`C`

is a categorical array, plots a histogram with a
bar for each category in `C`

.

`histogram(`

plots only the subset of categories specified by
`C`

,`Categories`

)`Categories`

.

`histogram('Categories',`

manually specifies categories and associated bin counts.
`Categories`

,'BinCounts',`counts`

)`histogram`

plots the specified bin counts and does
not do any data binning.

`histogram(___,`

specifies additional options with one or more `Name,Value`

)`Name,Value`

pair arguments using any of the previous syntaxes. For example, you can
specify `'BinWidth'`

and a scalar to adjust the width of
the bins, or `'Normalization'`

with a valid option
(`'count'`

, `'probability'`

,
`'countdensity'`

, `'pdf'`

,
`'cumcount'`

, or `'cdf'`

) to use a
different type of normalization. For a list of properties, see Histogram Properties.

`histogram(`

plots into the axes specified by `ax`

,___)`ax`

instead of into the
current axes (`gca`

). The option `ax`

can
precede any of the input argument combinations in the previous
syntaxes.

returns a `h`

= histogram(___)`Histogram`

object. Use this to inspect and
adjust the properties of the histogram. For a list of properties, see
Histogram Properties.

Histogram Properties | Control histogram appearance and behavior |

Histogram plots created using

`histogram`

have a context menu in plot edit mode that enables interactive manipulations in the figure window. For example, you can use the context menu to interactively change the number of bins, align multiple histograms, or change the display order.

Histogram Properties | `discretize`

| `fewerbins`

| `histcounts`

| `histcounts2`

| `histogram2`

| `morebins`

Was this topic helpful?