how can I change the color of the bar 2,4,6?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, so I got the code that makes me the figure bar, what I want is to change the color of the bar in position 2,4 and 6. Here is my code:
T=categorical(T); % turn into categorical variable
b = bar(T,C,'FaceColor','flat');
text(1:length(C),C,num2str(C'),'vert','bottom','horiz','center');
xlabel('Nombre missatges'); ylabel('Mesos')
title('Mitja de missatges de cada mes')
box off
I also attach the matlab data. Than you in advance
0 Kommentare
Akzeptierte Antwort
Voss
am 2 Mai 2022
load('sl.mat');
T=categorical(T); % turn into categorical variable
You can set the colors when you create the bar:
colors = get(gca(),'ColorOrder');
cdata = colors(ones(numel(T),1),:);
cdata([2 4 6],:) = [ ...
1 0 0; ... % red
0 1 0; ... % green
1 1 0]; % yellow
b = bar(T,C,'FaceColor','flat','CData',cdata);
Or you can set the colors after you create the bar:
b = bar(T,C,'FaceColor','flat');
cdata = get(b,'CData');
cdata([2 4 6],:) = [ ...
1 0 0; ... % red
0 1 0; ... % green
1 1 0]; % yellow
set(b,'CData',cdata);
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Bar Plots 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!