How to remove space between grouped bars in a bar graph?

15 ビュー (過去 30 日間)
Krishnashish Bose
Krishnashish Bose 2021 年 6 月 14 日
編集済み: Krishnashish Bose 2021 年 6 月 16 日
Adjusting space betwwen bars of a normal bar graph is pretty straightforward. However, there doesn't seem to be a way of doing the same for grouped bars. I am not asking about the space between bars of the same group, but the space between groups.

回答 (1 件)

Scott MacKenzie
Scott MacKenzie 2021 年 6 月 15 日
編集済み: Scott MacKenzie 2021 年 6 月 15 日
Here's an approach that might be useful. What if you ungroup the data first? There will be no space between the groups, because there are no groups per se. But, to retain the "grouping", you need the same color sequence as if the data were grouped. Below is the code. The bottom chart is what you are looking for (I think).
y1 = rand(3,4); % grouped data
y2 = reshape(y1',[], 1); % same data, ungrouped
tiledlayout(2,1);
nexttile;
b1 = bar(y1);
cd = [b1(:).FaceColor];
cd = reshape(cd',3,[])';
nexttile;
b2 = bar(y2, 'facecolor', 'flat'); % same data, same colors, no space between groups
b2.CData = repmat(cd, length(b2.XData)/size(cd,1),1);
  1 件のコメント
Krishnashish Bose
Krishnashish Bose 2021 年 6 月 16 日
編集済み: Krishnashish Bose 2021 年 6 月 16 日
Thanks Scott. What you mentioned is how I have been doing it, but it becomes confusing which bars are of the same or adjacent groups. I heard from Mathworks team today that it cannot be done currently, and they would introduce this feature in future versions of Matlab.

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

カテゴリ

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

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by