![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/283059/image.png)
Multiple Bars in a single plot along legend
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Usman Mussadiq
le 9 Avr 2020
Commenté : Ameer Hamza
le 9 Avr 2020
First of all, sorry, i am new one here, i do not know how to draw that plot whether it is too basic.
My Question is that
I have 5 users (on X-axis), Capacity(kW)/Cost(PKR) on Y-axis.
Capacity is further classified into Solar as well as storage. its range from 0-14
Three bar lines for each user.
Need Different colors for each Y axis element.
add legend also
Please help me.
0 commentaires
Réponse acceptée
Ameer Hamza
le 9 Avr 2020
Modifié(e) : Ameer Hamza
le 9 Avr 2020
try this
data = [1 2 1 3 2;
2 3 1 2 3;
3 2 1 2 1];
figure();
ax = axes();
bar(data', 'stacked')
xlabel('Users');
ylabel('Capacity(kW)/Cost(PKR)');
ax.XTickLabel = {'user1', 'user2', 'user3', 'user4', 'user5'};
legend({'class1', 'class2', 'class3'});
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/283059/image.png)
4 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!