changing color for each bar plot
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Prasad Joshi
am 16 Feb. 2022
Kommentiert: Prasad Joshi
am 17 Feb. 2022
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');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/896435/image.png)
0 Kommentare
Akzeptierte Antwort
Cris LaPierre
am 16 Feb. 2022
3 Kommentare
Cris LaPierre
am 16 Feb. 2022
Try this answer from 2016
Here's an example of my interpretation of how to do this.
percBar= {'EO_10','C1_10','C2_10','EO_45','C1_45','C2_45','EO_200','C1_200','C2_200'};
x = 1:9;
y = [75 91 105 123.5 131 150 179 203 226];
c = jet(length(y));
for a = 1:length(y)
b=bar(x(a),y(a),'FaceColor',c(a,:),'barwidth',0.9);
hold on
end
hold off
xticks(x)
xticklabels(percBar)
set(gca,'TickLabelInterpreter','none')
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!