Code covered by the BSD License  

Highlights from
Generalized Bar Charts

4.0

4.0 | 2 ratings Rate this file 14 Downloads (last 30 days) File Size: 4.31 KB File ID: #29635
image thumbnail

Generalized Bar Charts

by

 

06 Dec 2010 (Updated )

Stacked, Grouped, Clustered, Floating; and MIXED of any combination

| Watch this File

File Information
Description

Generalization of bar.m function.

Capable of producing:

1. Bar Chart
2. Floating Bar Chart
3. Clustered Bar Chart
4. Floating Clustered Bar Chart
5. Stacked Bar Chart
6. Stacked Clustered Bar Chart
7. (Multiple data sets)

As well as MIXED charts containing any combination of them on the same chart

Can also handle x-coordinate spacing and labeling, missing data, and legends.

EXAMPLES:
 
SIMPLE BAR CHART
data=rand(1,4);
bar2(data)
 
BAR CHART with spaced data and labels:
data=rand(1,4);
bar2([1 2 7 8],data,'BASE','XLABEL',{'A','B','C','D'})
 
FLOATING BAR CHART:
data=rand(2,4);
bar2([1 2 7 8],data,'XLABEL',{'A','B','C','D'})
 
BAR CHART WITH LOG AXIS AND USER SPECIFIED BASE:
data=rand(1,4);
bar2([1 2 7 8],data,'BASE',1e-3,'XLABEL',{'A','B','C','D'});
set(gca,'Yscale', 'log'), grid on;
 
CLUSTERED BAR CHART:
data=rand(3,4);
bar2([1 2 7 8],data,'BASE','XLABEL',{'A','B','C','D'})
 
FLOATING CLUSTERED BAR CHART:
data=rand(6,4); %Six rows representing three vertical [low high]
bar2(data)
legend({'A','B','C'},'Location','BestOutside')
 
FLOATING CLUSTERED BAR CHART: (with NaNs)
data=rand(6,4); data([3,4],[2 3])=NaN;
bar2(data)
legend({'A','B','C'},'Location','BestOutside')
 
STACKED BAR CHART:
data=rand(1,4,3); %Note: One row for one vertical column per category
bar2(data,'STACKED')
 
STACKED CLUSTERED BAR CHART:
data=rand(2,4,3); %Two clusters, both stacked
bar2([1 2 5 6],data,'STACKED','XLABEL',{2001,2002,2005,2006})
legend({'A','B','C','D','E','F'},'Location','BestOutside')
 
Multiple data sets on same X-coordinate:
data=rand(6,4,2);
data(:,:,2)=data(:,:,2)+max(data(:)); %for illustration
bar2(data,'XLABEL',{'A','B','C','D'})
 
MIXED CHARTS
(Bar chart + Clustered Bar Chart + Stacked Bar Chart + Floating)
alldata{1}={[1 2 6 10],rand(1,4),'BASE','XLABEL',{'B1','B2','B3','B4'}};
alldata{2}={[3 7 8 12],rand(3,4),'BASE','XLABEL',{'CB1','CB2','CB3','CB4'}};
alldata{3}={[4 5 11 13],rand(1,4,3),'STACKED','XLABEL',{'S1','S2','S3','S4'}};
alldata{4}={9,rand(2,1),'XLABEL',{'FLOAT'}};
bar2(alldata)
legend({'Bar','CB_1','CB_2','CB_3','V_1','V_2','V_3','Float'},'Location','BestOutside')

MATLAB release MATLAB 7.9 (R2009b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
29 Apr 2013 Mariana

Great code! Can we change color on the bars?

05 Apr 2012 Michael Crimmins

Really great to see a script that supports floating bar charts! I can't seem to change the face or edge color of the bars, though. Is this supported?

05 Apr 2012 Michael Crimmins  
Updates
07 Dec 2010

Modified:
6-Dec-2010 Non-zero VAL for BASE (Credit to J.R.G)

10 Dec 2010

10-Dec-2010 Modified code to handle mixed charts

14 Dec 2010

14-Dec-2010 Fixed bug: bar2(data) produces simple bar chart

14 Sep 2011

Updated H1 line, and description

04 Apr 2012

Updated help section

Contact us