how to label y axis

3 ビュー (過去 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 Center および File ExchangeDiscrete Data Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by