Is it possible to set the size of the gap between grouped bars in a bar graph?
90 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
the cyclist
2020-6-30
编辑:the cyclist
2020-6-30
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 个)
Benjamin Kraus
2024-4-26
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 个评论
the cyclist
2020-6-30
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!