Effacer les filtres
Effacer les filtres

How to show all xtick labels in a barplot?

91 vues (au cours des 30 derniers jours)
VS
VS le 31 Mar 2022
Commenté : Star Strider le 31 Mar 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.

Réponse acceptée

Star Strider
Star Strider le 31 Mar 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 commentaires
VS
VS le 31 Mar 2022
Thanks, it worked.
Star Strider
Star Strider le 31 Mar 2022
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by