Is it possible to set the size of the gap between grouped bars in a bar graph?
94 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Heidi Hirsh
le 30 Juin 2020
Réponse apportée : Benjamin Kraus
le 26 Avr 2024
I know you can set the width of each bar (I set mine near max) but I am curious if I can minimize the white space by decreasing the x distance between each pair (group) of bars.
This is what I am plotting:
coh = [0.9862, 0.9773
0.971, 0.9544
0.8969, 0.6791
0.8835, 0.9051
0.8558, 0.6727
0.6727, 0.8641];
figure
hB=bar(coh,.95);
Thank you!
0 commentaires
Réponse acceptée
the cyclist
le 30 Juin 2020
Modifié(e) : the cyclist
le 30 Juin 2020
Another option would be to abandon using grouped bars in a single call to bar(), and instead plot the two sets of bars with two different calls to bar(), and specifying the x locations of those bars.
figure
hold on
w = 0.4;
bar((1:6)-w/2,coh(:,1),w)
bar((1:6)+w/2,coh(:,2),w)
2 commentaires
Plus de réponses (2)
Benjamin Kraus
le 26 Avr 2024
Starting in R2024a, you can now customize the width of each group of bars using the new GroupWidth property.
For example:
coh = [0.9862, 0.9773
0.971, 0.9544
0.8969, 0.6791
0.8835, 0.9051
0.8558, 0.6727
0.6727, 0.8641];
figure
hB=bar(coh,.95);
set(hB, GroupWidth = 0.95);
0 commentaires
the cyclist
le 30 Juin 2020
This question and the answer from MATLAB staff suggest that it is not possible using the built-in bar function.
However, there is another answer from someone who contributed the barmod function to the File Exchange, claiming to solve this problem. It's quite new, and I have not tried it, but it might be worth a shot.
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!