Control Bars Color
Hereafter are presented the available ways of controling bars colors depending on their X or Y values.
- Set the condition that will define different colors.
- Define bars into ranges based on the condition.
- Use overlay to have all ranges in the same graph.
Abscissa based formatting
Fill in green all bars beyond x = 5.⎘
x = (1:20)% initializing X and Y values
y = [9,4,6,1,1,5,3,7,9,10,2,3,8,5,6,1,3,8,6,4] c = x<=5% Condition
o1 = struct% initializing options struct
o1.show = false b1 = bar(x(c),y(c),o1)% Range 1: bars with x minor or equal to 5
o2 = o1% initializing options struct
o2.barFill = 'green' b2 = bar(x(~c),y(~c),o2)% Range 2: bars with x major to 5
overlay({b1,b2})% All ranges together
Ordinates based formatting
Fill in green all bars smaller than y = 6.⎘
x = (1:20)% initializing X and Y values
y = [9,4,6,1,1,5,3,7,9,10,2,3,8,5,6,1,3,8,6,4] c = y>6% Condition
o1 = struct% initializing options struct
o1.show = false b1 = bar(x(c),y(c),o1)% Range 1: bars with y major than 6
o2 = o1% initializing options struct
o2.barFill = 'green' b2 = bar(x(~c),y(~c),o2)% Range 2: bars with y minor or equal to 6
overlay({b1,b2})% All ranges together