필터 지우기
필터 지우기

Bar graphs - color coding..

조회 수: 2 (최근 30일)
sas0701
sas0701 2013년 3월 5일
Hello,
I need to color code my bar graph.
a = [10 20 30 25 15] b = [1 3 2 1 4] bar(a)
BUT, I want a(1) and a(4) the same color because b(1) and b(4) = 1; a(2), a(3) and a(5) each a different color because b(2,3 and 5) are different.
Thanks, S

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 3월 5일
close
a = [10 20 30 25 15]
b = [1 3 2 1 4]
cl='rgbmc'
for k=1:numel(a)
bar(k,b(k),cl(b(k)))
hold on
end
set(gca,'Xtickmode','auto')
set(gca,'Xtick',1:k)

추가 답변 (1개)

sas0701
sas0701 2013년 3월 5일
Hi, For reasons beyond my control , I need to specify the colors colors = [0 0 1; %blue 1 0 1; %magenta 0 1 0; %green 1 0 0; %red 0 1 1; %cyan 1 1 0; %yellow 0 0 0; %black 1 0.5 0]; %orange
Is there anyway to do this in bar graph. The only problem seems to be orange as the others have a short name associated with it.
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2013년 3월 5일
편집: Azzi Abdelmalek 2013년 3월 6일
close
a = [10 20 30 25 15]
b = [1 3 2 1 4]
cl= [0 0 1; 1 0 1;0 1 0;1 0 0; 0 1 1; 1 1 0; 0 0 0; 1 0.5 0];
for k=1:numel(a)
h=bar(k,b(k),'Facecolor',cl(b(k),:))
hold on
end
sas0701
sas0701 2013년 3월 6일
Of course that works!! I had tried it before but yours works :) Thank you!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by