Combine “grouped” and “stacked” in the BAR?

I know how to draw a groupedBAR graph and a stackedBAR graph 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 create something like:

enter image description here

My question is that how can I combine settings groupedand stackedin the BAR chart , to be able to generate a figure similar to the following (3.4 stack together)? Or is there an alternative way to achieve this? Postscript I manually drew the following image.

enter image description here

+4
source share
1 answer

I finally found a way to do this, the idea is this:

, :

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

:

enter image description here

+3

Source: https://habr.com/ru/post/1523304/


All Articles