フィルターのクリア

How to show all xtick labels in a barplot?

91 ビュー (過去 30 日間)
VS
VS 2022 年 3 月 31 日
コメント済み: Star Strider 2022 年 3 月 31 日
I have a .csv file that contains some ratios for all the US states. I am trying to make a barplot using these ratios (which means 51 bars). I want the names of all territories as tick labels on the x-axis. But I could not make it work Here is what I have done so far:
mydata = readtable('bardata.csv');
mydata_sorted = sortrows(mydata, 4);
bar(mydata_sorted{:,4}); xticklabels(mydata_sorted{:,1});
xtickangle(90);
Will appreciate any help.

採用された回答

Star Strider
Star Strider 2022 年 3 月 31 日
Try this —
mydata = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/948329/bardata.csv');
mydata_sorted = sortrows(mydata, 4);
bar(mydata_sorted{:,4});
set(gca,'XTick',1:numel(mydata_sorted{:,1}), 'XTickLabel',mydata_sorted{:,1})
xtickangle(90);
It might be necessary to use the 'Position' property to estend the plot width to make the tick labels less crowded.
.
  2 件のコメント
VS
VS 2022 年 3 月 31 日
Thanks, it worked.
Star Strider
Star Strider 2022 年 3 月 31 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by