bar

Creates bars in an axis and returns handles of the bars.

Syntax

h = bar(x, y)

h = bar(x-categories, y)

h = bar(..., width)

h = bar(..., style)

h = bar(..., property, value, ...)

h = bar(hAxes, ...)

Inputs

x,y
Range of the x and y axes.
Type: double | integer
Dimension: string | vector | matrix
x-categories
Names of the categories.
Type: string
Dimension: cell
width
The bar width.
Type: double | integer
Dimension: scalar
style
Style of each groups of bars. Either "grouped" (default style) or "stacked."
Type: string
Dimension: scalar
property
Properties that control the appearance or behavior of the graphics object.
Type: string
Dimension: scalar
value
Value of properties.
Type: double | integer | string
Dimension: scalar | vector
hAxes
Axis handle.
Type: double
Dimension: scalar

Outputs

h
Handle of the bar graphics object.

Examples

Simple bar example:
clf;
a=bar([1 2 3], [1 3 2; 3 2 1]);
Figure 1. Bar plot

Simple bar with multi-format tags:
clf;
a=bar([1 2 3], [1 3 2; 3 2 1], 'facecolor', [141 179 226]);
get(a)
Figure 2. Bar plot with options

bar with category values on the x axis:
clf;
bar({'apple', 'banana'}, [1 2]);
Figure 3. Bar plot with category values on the x axis

Comments

If there is no axis, one will be created . If x is omitted, the index of y is used as data to associate with the x axis. If the first argument of bar() is an axis handle, the bars will be created in that axis.