bar

Single vector input

y = [10 12 13]
bar(y)

Controlling horizontal position

options = struct
options.barFill = '#DCDCDC'
options.barWidth = 0.4
options.barStroke = '#808080'
options.barStrokeWidth = 2
x = 10:15
y = [5 7 4 1 6 3]
bar(x, y, options)

Changing base level

options = struct
options.barBase = 80
options.yAxisMin = 80
y = [100 122 93]
bar(y, options)

Grouped bar chart

y = [1 2 3; 4 5 6]
bar(y)

Stacked bar chart

options.barStack = true
y = [1 2 3; 4 5 6]
bar(y, options)

Specifying colors and labels

options = struct
options.areaColors = {'pink' 'lightblue'}
options.xAxisLabels = {'A' 'B' 'C' 'D' 'E'}
x = [ 20 25; 35 32; 30 34; 35 20; 27 25]
bar(x, options)

Table input

options = struct
options.areaColors = {'pink' 'lightblue'}
options.xAxisLabels = {'A' 'B' 'C' 'D' 'E'}
options.barStack = true
x = table ([20; 35; 30; 35; 27], [25; 32; 34; 20; 25], 'Variablenames', {'women ', 'men'})
bar(x, options)

Overlaying bars

op1 = struct('show', false)
op2 = op1
op1.barFill = 'darkgray'
op1.barWidth = 0.2
op1.xAxisLabels = {'w1' 'w2' 'w3' 'w4' 'w5' 'w6'}
op2.barFill = '#DCDCDC'
op2.barOpacity = 0.7
y1 = 100:100:600
y2 = [70 300 400 200 600 500]
s1 = bar(y1, op1)
s2 = bar(y2, op2)
overlay({s1, s2})

See also

plot | area | histogram