MATLAB: How to change color of individual bar graph.

MATLABplotting

y = [21000 65000 65000 65000 ; 16000 50000 50000 50000 ; 11000 34000 34099 34101; 6299 19500 19299 19300; 7701 37899 37901 37801];
bar(y);
ylabel('Y-data')
xlabel('X-data')
audit = {'audit1' 'audit2' 'audit3' 'audit4'};
legend(audit,'location','northeast')
I want to set color of all 4 different bars(audit1,…) manually.

Best Answer

clc; clear all ;
y = [21000 65000 65000 65000 ; 16000 50000 50000 50000 ; 11000 34000 34099 34101; 6299 19500 19299 19300; 7701 37899 37901 37801];
bar_handle = bar(y,'grouped');
set(bar_handle(1),'FaceColor','r') ;
set(bar_handle(2),'FaceColor','b') ;
set(bar_handle(3),'FaceColor','y') ;
set(bar_handle(4),'FaceColor','g') ;
ylabel('Y-data')
xlabel('X-data')
audit = {'audit1' 'audit2' 'audit3' 'audit4'};
legend(audit,'location','northeast')