Code covered by the BSD License  

Highlights from
Bar with errorbars

5.0

5.0 | 2 ratings Rate this file 33 Downloads (last 30 days) File Size: 1.77 KB File ID: #24718
image thumbnail

Bar with errorbars

by Venn Ravichandran

 

13 Jul 2009 (Updated 22 Jun 2011)

This code plots bars with errorbars, as simple as that.

| Watch this File

File Information
Description

As of now (2009-Jul-13), MATLAB doesn't have a built-in function to plot bars with with error bars on top of them. This function solves that problem.

To a beginning user, this provides a very simple way of plotting bar with errorbars with a simple command:
errorbarbar(y,e); % where y is the height of the bars and e is the limit to plot as error bars (of length 2*e, about y).

For an intermediate user, this function provides the handles to the BAR and ERRORBAR lines for further modification.
[b,e] = errorbarbar(y,e); % or ...
[b,e] = errorbarbar(x,y,e); % where x is center location of the group of bars

For an advanced user, this function also provides ways to modify any and all of the bar and line series properties while plotting it in the first place.

Example:
barSettings = {'facealpha',0.5,'edgecolor',[0.5 0.5 0.5]};
lineSettings = {'linestyle','--','linewidth',2};
[b,e] = errorbarbar(x,y,e,barSettings,lineSettings);
set(b,'facecolor',[0 0.5 0]); % set all bars to color green

Hint: You can use the lineSettings variable to use distinct upper and lower limits.

What it DOESN'T do:
1. Plot horizontal bar graphs
2. Work with bar(y,e,barSettings,lineSettings). Instead, use:
      bar(x,y,e,barSettings,lineSettings).

MATLAB release MATLAB 7.5 (R2007b)
Other requirements Because of the way this function is written, it should be backwards/upwards compatible, as long as BAR and ERRORBAR functions are consistent with R2007b.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (7)
02 Jun 2011 Shatrughan

It is not as simple as you said. Would you mind putting up an illustrative example (especially for stacked bar plot). I would really appreciated it.

Thanks,
Shatrughan

03 Jun 2011 Venn Ravichandran

@Shatrughan: errorbarbar(1:5, rand(5,2)*10, rand(5,2),{'stacked'});

07 Jun 2011 Shatrughan

Thanks a lot !!

19 Oct 2011 sinoTrinity Liu

"Hint: You can use the lineSettings variable to use distinct upper and lower limits."
Can you give me an example? I need to draw asymmetric error bounds. Thanks.

19 Oct 2011 Venn Ravichandran

x = 1:10; % x-axis
y = rand(10,2); % bar-heights
L = rand(10,2)*0.01; % Lower limit
U = rand(10,2)*0.03; % Upper limit
barSettings = {};
lineSettings = {U, 'linestyle', 'none'};
errorbarbar(x, y, L, barSettings, lineSettings);

19 Oct 2011 Shatrughan  
16 Dec 2011 Xiaohui Liu

Other error bars I find cannot deal with asymmetric error bounds. This one works like a charm.

Please login to add a comment or rating.
Updates
14 Jul 2009

Changed a bug which caused the program to give an error if either the barSettings or lineSettings was empty.

15 Jul 2009

Now works with stacked bars as well.

22 Jun 2011

Error bars no longer have legends of their own. If you want them back on, then comment out line 63 :)

Tag Activity for this File
Tag Applied By Date/Time
bar Venn Ravichandran 14 Jul 2009 10:20:02
errorbar Venn Ravichandran 14 Jul 2009 10:20:02
gui Venn Ravichandran 14 Jul 2009 10:20:02
data visualization Venn Ravichandran 14 Jul 2009 10:20:02

Contact us at files@mathworks.com