how to assign names to each bar of a bar chart
71 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponse acceptée
C.J. Harris
le 28 Mar 2012
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 commentaire
Plus de réponses (2)
ORUGANTI SIVAMURALIKRISHNA
le 5 Juil 2020
Use like this
X = categorical({'Small','Medium','Large','Extra Large'});
Y = [0 15 20 25];
bar(X,Y)
2 commentaires
Bill Tubbs
le 15 Juin 2021
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
le 27 Juin 2021
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
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!