How to change distance between groups of bars in a bar plot?

30 visualizaciones (últimos 30 días)
Ovidiu
Ovidiu el 5 de Dic. de 2014
Respondida: Benjamin Kraus hace alrededor de 17 horas
I have 3 sets of data that I am plotting using 'bar'. This generates sets of grouped bars. I know one can change the width of bars such that within a group they have some gap between them.
But how do I change the distance between groups of bars? I could not find any solution online, except calculating the x coordinates by yourself and plotting each dataset separately. If that's the only way, Mathworks should do something about it!
  2 comentarios
dpb
dpb el 5 de Dic. de 2014
Not sure what's wrong with that...what would you want some automagic input parameter to specify except the same thing that you would still have to calculate?
There's no need to plot datasets separately, simply use the x-spacing you calculate in the call to bar You may have to rearrange ticks and tick labels if the spacing doesn't reflect the desired labels.
Without an example of what you're trying to create can't say more than generalities...attach a sample???
dpb
dpb el 18 de Dic. de 2021
OK, I just ran into the issue -- with a fairly sizable number of bars/group, there's a lot of wasted white space between the bar groups that could be utilized to make the bars within the groups wider. Here's the one that getting here...even if you stretch the axis height by making figure larger, the corresponding whitespace just grows proportionally..
To get these as wide as they are took closing up ylim, setting 'Width',1 and reducing fontsizes for title and labels and putting the subtitle as the legend title and putting it 'eastoutside' instead of four-column wide at bottom. Still there's insufficient bar witdth for the values to fit while there's still not enough room for values unless make fontsize even smaller. Meanwhile, there's all that white real estate in between the groups...

Iniciar sesión para comentar.

Respuestas (2)

Hunter Pruett
Hunter Pruett el 23 de Mayo de 2020
Just finished the barmod function--controls relative position of just about everything in the plot. Hope this helps anyone else with this question.

Benjamin Kraus
Benjamin Kraus hace alrededor de 17 horas
Starting in R2024a, you can now customize the width of each group of bars using the new GroupWidth property.
For example:
nexttile
bar(magic(5), GroupWidth=0.4);
nexttile
bar(magic(5), GroupWidth=1);

Categorías

Más información sobre Line 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!

Translated by