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

49 vues (au cours des 30 derniers jours)
Ovidiu
Ovidiu le 5 Déc 2014
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 commentaires
dpb
dpb le 5 Déc 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 le 18 Déc 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...

Connectez-vous pour commenter.

Réponse acceptée

Benjamin Kraus
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:
nexttile
bar(magic(5), GroupWidth=0.4);
nexttile
bar(magic(5), GroupWidth=1);

Plus de réponses (1)

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

Catégories

En savoir plus sur Data Distribution 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!

Translated by