フィルターのクリア

how to assign names to each bar of a bar chart

367 ビュー (過去 30 日間)
Kirk
Kirk 2012 年 3 月 28 日
コメント済み: ZenithWoman 2021 年 6 月 27 日
Hello, Suppose i have some data that i want to plot in a bar chart. How do i assign labels to each of the bars. e.g.
somedata=randn(1,3)
somenames={'mike'; 'steve'; 'alex' }
barh(somedata)
My question is, how do i label each of the bars to the extreme left with the names.
Thank you for your help.

採用された回答

C.J. Harris
C.J. Harris 2012 年 3 月 28 日
You can simply add the names as the y-tick labels.
somedata=randn(1,3);
somenames={'mike'; 'steve'; 'alex' };
barh(somedata)
set(gca,'yticklabel',somenames)
  1 件のコメント
emjey
emjey 2019 年 5 月 17 日
編集済み: emjey 2019 年 5 月 17 日
But that doens't work if you have more than 20-30 data records :(
In such case Matlab plots the first few labels only...

サインインしてコメントする。

その他の回答 (2 件)

ORUGANTI SIVAMURALIKRISHNA
ORUGANTI SIVAMURALIKRISHNA 2020 年 7 月 5 日
Use like this
X = categorical({'Small','Medium','Large','Extra Large'});
Y = [0 15 20 25];
bar(X,Y)
  2 件のコメント
Bill Tubbs
Bill Tubbs 2021 年 6 月 15 日
Is there a reason why it sorts the data along the x-axis in alphabetical order? Is there any way to preserve the order?
ZenithWoman
ZenithWoman 2021 年 6 月 27 日
To preserve the order write
Write like this
X = categorical({'Small','Medium','Large','Extra Large'});
X = reordercats(X,{'Small','Medium','Large','Extra Large'});
Y = [0 15 20 25];
bar(X,Y)
I hope this helps

サインインしてコメントする。


Sarul Gupta
Sarul Gupta 2017 年 5 月 4 日
Thanks :)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by