Filter löschen
Filter löschen

How to show all xtick labels in a barplot?

91 Ansichten (letzte 30 Tage)
VS
VS am 31 Mär. 2022
Kommentiert: Star Strider am 31 Mär. 2022
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.

Akzeptierte Antwort

Star Strider
Star Strider am 31 Mär. 2022
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 Kommentare
VS
VS am 31 Mär. 2022
Thanks, it worked.
Star Strider
Star Strider am 31 Mär. 2022
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by