histogram
Create histogram plot.
📝Syntax
histogram(X)
histogram(X, nbins)
histogram(X, edges)
histogram(C)
histogram(C, categories)
histogram(..., propertyName, propertyValue)
histogram(ax, ...)
h = histogram(...)
📥Input Arguments
Parameter Description
X numeric input data.
nbins number of bins.
edges strictly increasing bin edges.
C categorical input data.
categories cell array of character vectors or string array selecting the categories to display and their order.
propertyName histogram object property name.
propertyValue histogram object property value.
ax target axes object.
📤Output Arguments
Parameter Description
h histogram graphics object.
📄Description

histogram bins numeric data and displays the bin values as bars or stairs.

When C is a categorical array, histogram draws one bar per category, with a bar height equal to the number of elements in that category. The bars are displayed in category order (as returned by categories), and the category names are used as tick labels. A second argument may list the categories to display and their order.

See histogram properties for the complete property list.

💡Examples
x = [1 1 2 2 2 3 4 4 5];
histogram(x);
Example illustration
x = randn(200, 1);
histogram(x, 12, 'Normalization', 'probability', 'FaceAlpha', 0.5);
Example illustration
x = [1 1 2 3 3 4 5];
h = histogram(x, [0 2 4 6], 'DisplayStyle', 'stairs');
h.LineWidth = 1.5;
Example illustration
Categorical histogram: one bar per category, counts in category order.
C = categorical({'small', 'medium', 'large', 'small', 'medium', 'small'});
histogram(C);
Example illustration
🔗See Also
histogram propertieshistbar
Edit this page on GitHub