bar
Bar graph.
📝Syntax
bar(Y)
bar(X, Y)
bar(..., width)
bar(..., color)
bar(..., propertyName, propertyValue)
bar(ax, ...)
b = bar(...)
📥Input Arguments
Parameter Description
X x-coordinates: scalar, vector or string array.
Y y-coordinates: vector.
width scalar, 0.8 (default).
color a scalar string or row vector character: color name or short color name.
propertyName a scalar string or row vector character.
propertyValue a value.
ax Axes object.
📤Output Arguments
Parameter Description
b patch graphics object.
📄Description

bar(X, Y) creates a bar graph using two sets of X-Y data vectors.

When only one argument is provided (Y), it is interpreted as a vector containing Y values, and the X coordinates are generated as a sequence from 1 to the number of elements in the Y vector.

You can optionally specify the width of the bars.

A value of 1.0 will make each bar exactly touch its neighboring bars, while the default width is set to 0.8.

💡Examples
f = figure();
y = [ 91 75 123.5 105 150 131 203 179 249 226 281.5];
bar(y);
Example illustration
f = figure();
y = [ 91 75 123.5 105 150 131 203 179 249 226 281.5];
bar(y, 0.5);
Example illustration
f = figure();
x = 1900:10:2000;
y = [75 91 105 123.5 131 150 179 203 226 249 281.5];
bar(x, y, 'r');
Example illustration
f = figure();
x = [ "Summer", "Spring", "Winter", "Autumn"];
y = [ 2 1 4 3];
bar(x, y);
Example illustration
f = figure();
y = [91 75 123.5 105 150 131 203 179 249 226 281.5];
bar(y, 'FaceColor', [0 .5 .5], 'EdgeColor', [0 .9 .9], 'LineWidth', 1.5)
Example illustration
🔗See Also
histpatch
🕔Version History
Version Description
1.0.0 initial version
1.12.0 Color name or short color name managed.
Edit this page on GitHub