필터 지우기
필터 지우기

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 CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by