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

51 ビュー (過去 30 日間)
Ovidiu
Ovidiu 2014 年 12 月 5 日
回答済み: Benjamin Kraus 2024 年 4 月 26 日
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 件のコメント
dpb
dpb 2014 年 12 月 5 日
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 2021 年 12 月 18 日
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...

サインインしてコメントする。

採用された回答

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

その他の回答 (1 件)

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

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by