how can I change the color of the bar 2,4,6?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Bar Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!