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 Center および File ExchangeBar Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by