her*_*tao 5 matlab plot bar-chart
我知道如何绘制groupedBAR图和stackedBAR图如下:
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')
Run Code Online (Sandbox Code Playgroud)
这将产生类似于:

我的问题是如何组合选项grouped和stackedBAR图中能够生成如下图(堆栈3,4在一起)?或者有没有其他方法来实现这一目标?PS我手动绘制了下图.

我终于找到了办法,这个想法是:
绘制堆叠条形图(需要plotBarStackGroups.m).
设置额外的零以模拟原始组.
将这些组合在一起,代码将类似于:
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
Run Code Online (Sandbox Code Playgroud)
结果将是:
