필터 지우기
필터 지우기

how to label y axis

조회 수: 2 (최근 30일)
Ibrahim AlZoubi
Ibrahim AlZoubi 2020년 5월 6일
댓글: Tommy 2020년 5월 6일
how to label each row of these 3 saws:
i want to call them: A,B, and C.
also how to color each raw?
this is my code:
x =[208,237,248];
barh (x)
axis square

채택된 답변

Benjamin Colety
Benjamin Colety 2020년 5월 6일
try this for the labels
labels={'A'; 'B'; 'C' };
barh(x)
set(gca,'yticklabel',labels)
  댓글 수: 4
ibrahim alzoubi
ibrahim alzoubi 2020년 5월 6일
how to change the colors?
Tommy
Tommy 2020년 5월 6일
You can set the FaceColor property to any rgb value:
x =[208,237,248];
colors = [ 1 0 0 ; % red
0 1 0 ; % blue
0 0 1 ]; % green
hold on
for i=1:numel(x)
barh(i, x(i), 'FaceColor', colors(i,:))
end
axis square
yticks(1:numel(x))
yticklabels({'A'; 'B'; 'C'})
Or, honestly this is simpler:
x =[208,237,248];
colors = [ 1 0 0 ; % red
0 1 0 ; % blue
0 0 1 ]; % green
barh(x, 'FaceColor', 'flat', 'CData', colors);
axis square
yticklabels({'A'; 'B'; 'C'})

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by