how can I change the color of the bar 2,4,6?

조회 수: 1 (최근 30일)
flashpode
flashpode 2022년 5월 2일
답변: Voss 2022년 5월 2일
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

채택된 답변

Voss
Voss 2022년 5월 2일
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개)

카테고리

Help CenterFile Exchange에서 Bar Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by