![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/324109/image.png)
Is it possible to set the size of the gap between grouped bars in a bar graph?
59 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Heidi Hirsh
am 30 Jun. 2020
Beantwortet: Benjamin Kraus
am 26 Apr. 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 Kommentare
Akzeptierte Antwort
the cyclist
am 30 Jun. 2020
Bearbeitet: the cyclist
am 30 Jun. 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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/324109/image.png)
2 Kommentare
Weitere Antworten (2)
Benjamin Kraus
am 26 Apr. 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 Kommentare
the cyclist
am 30 Jun. 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.
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!