Graphing Same color every iteration in stacked bar chart
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Leta A
le 27 Nov 2020
Réponse apportée : Amrtanshu Raj
le 1 Déc 2020
Hello! I am trying to create a stacked bar chart in a loop that retains its original color for every iteration. I don't care what the colors are, I just don't want them to change. It's a single bar with only two stacks: I'm basically counting down from 20 every time a "player" picks a number. This is what I have, but every time the player makes a new move in my while loop, the colors change. I'm also wondering how to change the label on the bar graph to "Sticks" instead of the number 1.
I'm still learning matlab, but it seems like you can do more with the plot function than the bar graph??
barchart = bar(1,[sticks 20-sticks],'stacked');
title('Number of sticks left')
hold on
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/431533/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/431538/image.jpeg)
0 commentaires
Réponse acceptée
Amrtanshu Raj
le 1 Déc 2020
Hi,
barchart = bar(1,[sticks 20-sticks],'stacked');
barchart(1).FaceColor = 'r'; %set facecolor for lower bar
barchart(2).FaceColor = 'g'; %set facecolor for upper bar
ax = barchart.Parent;
ax.XTick = sticks; %set Xtick value to sticks
title('Number of sticks left')
hold on
Hope it helps !!
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Bar 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!