changing color for each bar plot
Show older comments
How can i can change color for each color in bar plot . I am saving all this values in an percBar and doing a bar plot how can I change the individual color for an bar like for first 3 it should be red , next 3 blue and last green .. I tried but it is taking the last color only i.e green .... How can I add set of 3 color to the plot ......Thank you in advance....I am using 2016B matlab version
t= [ 200 500 1000]
%% O2 Pollutant
% t=[572,922,2000]; %%% Time to measure the Pollutant Scores
EO_10=round(FlowMng_v401_1_O2_sim_mass_cum(t(1)));
EO_45=round(FlowMng_v401_1_O2_sim_mass_cum(t(2)));
EO_200=round(FlowMng_v401_1_O2_sim_mass_cum(t(3)));
%%% score at times After TWC1 Conditions
C1_10=round(BK401d1_1_O2_sim_mass_cum(t(1)));
C1_45=round(BK401d1_1_O2_sim_mass_cum(t(2)));
C1_200=round(BK401d1_1_O2_sim_mass_cum(t(3)));
%%% score at times After TWC2 Conditions
C2_10=round(BK401d1_2_O2_sim_mass_cum(t(1)));
C2_45=round(BK401d1_2_O2_sim_mass_cum(t(2)));
C2_200=round(BK401d1_2_O2_sim_mass_cum(t(3)));
%%% Plottting
hold on
percBar= [EO_10,C1_10,C2_10,EO_45,C1_45,C2_45,EO_200,C1_200,C2_200];
%%% plotting with different colours
col=[ 'r' 'r' 'r' 'b' 'b' 'b' 'g' 'g' 'g'] % setting color
xtics=[1:1:9]
h= bar(xtics,percBar)
for i= 1:3:9
set(h,'FaceColor',col(i)) % adding facecolor to the bar plot
end
xticlab={'EO-10' 'C1-10' 'C2-10' 'EO-45 ' 'C1-45' 'C2-45' 'EO-200' 'C1-200' 'C2-200'};
set(gca,'XTick',xtics,'XTickLabel',xticlab,'Fontsize',8)
text(xtics,percBar,num2str(percBar'),'vert','bottom','horiz','center');

Accepted Answer
More Answers (0)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
