将“分组"和“堆叠"合并到BAR图中? [英] Combine the 'grouped' and 'stacked' in a BAR plot?
问题描述
我知道如何绘制grouped
BAR图和stacked
BAR图,如下所示:
I know how to draw a grouped
BAR plot and a stacked
BAR plot as follows:
Y = round(rand(5,4)*10);
figure;
subplot(2,2,1); bar(Y,'grouped'); title('Group') % similar for 'hist'/'histc'
subplot(2,2,2); bar(Y,'stacked'); title('Stack')
这将生成类似以下内容的
This will generate something like:
我的问题是如何在条形图中组合选项grouped
和stacked
以生成如下图(将3,4叠加在一起)?还是有其他替代方法可以实现这一目标? P.S.我手动绘制了下图.
My question is that how can I combine options grouped
and stacked
in a BAR plot to be able to generate a figure like the following (stack 3,4 together)? Or is there any alternative way to achieve this? P.S. I manually drew the following figure.
推荐答案
我终于找到了一种方法,想法是:
I finally found a way to do this, the idea is:
-
绘制堆积条形图组(需要
plotBarStackGroups.m
).
设置额外的零以模拟原始组.
Setting extra zeros to simulate original groups.
将这些组合在一起,代码将类似于:
Combining these together, the code will be something like:
Y = round(rand(5,3,2)*10);
Y(1:5,1:2,1) = 0; % setting extra zeros to simulate original groups.
groupLabels = { 1, 2, 3, 4, 5}; % set labels
plotBarStackGroups(Y, groupLabels); % plot groups of stacked bars
结果将是:
这篇关于将“分组"和“堆叠"合并到BAR图中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!