Code covered by the BSD License  

Highlights from
Plot Groups of Stacked Bars

5.0
5.0 | 7 ratings Rate this file 67 Downloads (last 30 days) File Size: 1.69 KB File ID: #32884
image thumbnail

Plot Groups of Stacked Bars

by

Evan

 

Generate a bar plot with multiple stacks grouped together.

| Watch this File

File Information
Description

Plot a set of stacked bars, but group them according to labels provided.

Params:
     stackData is a 3D matrix (i.e., stackData(i, j, k) => (Group, Stack, StackElement))
     groupLabels is a CELL type (i.e., { 'a', 1 , 20, 'foo' };)

Acknowledgements

This file inspired Machine Learning With Matlab.

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (9)
18 Jul 2014 Jenny

Jenny

 
01 Apr 2014 Vera

Vera

 
13 Oct 2013 Ricardo

Ricardo

Very useful function!, thank you!

25 Aug 2013 Tim

Tim

Berk, I had the same desire and found it was pretty simple to customize.

After this...
h(i,:) = bar(Y, 'stacked');

I added this...
set(h(i,1),'facecolor','y','edgecolor','k');
set(h(i,2),'facecolor','r','edgecolor','k');
set(h(i,3),'facecolor','c','edgecolor','k');
set(h(i,4),'facecolor','g','edgecolor','k');

...so that the base of each bar is always yellow, etc.

Doubt you'll need this 1 year later, but for the next rookie like myself, could be useful.

Thanks for the elegant and useful function, Evan.

12 Mar 2013 Ben

Ben

 
21 Aug 2012 Berk

Berk

Thanks, very handy function!

Could you please tell whether we can assign different colors to different stacks?
Currently, all the stack elements have the same color/type. However, I am wonering whether it would be possible to differentiate the different stacks?

Comment only
21 Aug 2012 Berk

Berk

 
21 Oct 2011 grega

grega

Nice one! Works! Example makes it clear! Thank you!

14 Sep 2011 Evan

Evan

Example usage:

NumStacksPerGroup = 3;
NumGroupsPerAxis = 6;
NumStackElements = 4;

% labels to use on tick marks for groups
groupLabels = { 'Test'; 2; 4; 6; 8; -1; };
stackData = rand(NumGroupsPerAxis,NumStacksPerGroup,NumStackElements);

plotBarStackGroups(stackData, groupLabels);
set(gca,'FontSize',18)
set(gcf,'Position',[100 100 720 650])
grid on
set(gca,'Layer','top') % put grid lines on top of stacks

Comment only

Contact us