![](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?
56 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Heidi Hirsh
el 30 de Jun. de 2020
Respondida: Benjamin Kraus
el 26 de Abr. de 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 comentarios
Respuesta aceptada
the cyclist
el 30 de Jun. de 2020
Editada: the cyclist
el 30 de Jun. de 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 comentarios
Más respuestas (2)
Benjamin Kraus
el 26 de Abr. de 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 comentarios
the cyclist
el 30 de Jun. de 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.
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!