Changing color in grouped barplot in Matlab
You can use the 'FaceColor'
property of the handles to the objects:
n=[46.4000 51.8000
44.8000 44.9000
67.2000 85.0000
54.4000 60.3000
43.2000 57.0000
51.2000 68.0000
75.2000 76.0000
44.8000 51.3000
67.2000 72.2000
70.4000 71.2000];
bar_handle = bar(n,'grouped');
set(bar_handle(1),'FaceColor',[0,1,0])
set(bar_handle(2),'FaceColor',[1,1,0])
The documentation explains how to set the colors here.
For matlab2014b and higher
Using set
doesn't seem to work anymore since matlab2014b and gives the Message (Error using subsindex: Function 'subsindex' is not defined for values of class 'matlab.graphics.chart.primitive.Bar'.
).
Try it directly with the handle:
n=[46.4000 51.8000
44.8000 44.9000
67.2000 85.0000
54.4000 60.3000
43.2000 57.0000
51.2000 68.0000
75.2000 76.0000
44.8000 51.3000
67.2000 72.2000
70.4000 71.2000];
bar_handle = bar(n,'grouped');
bar_handle(1).FaceColor = 'r'
bar_handle(2).FaceColor = 'b'