Code covered by the BSD License  

Highlights from
Create Healthy Looking Error Bars

5.0

5.0 | 4 ratings Rate this file 77 Downloads (last 30 days) File Size: 4.16 KB File ID: #27387
image thumbnail

Create Healthy Looking Error Bars

by Jonathan C. Lansey

 

27 Apr 2010 (Updated 20 Oct 2011)

Plots nice error bars as the default. Can also top group plots with error bars.

| Watch this File

File Information
Description

% Description errorb(x,y,varargin)
errorb(Y,E) plots Y and draws an error bar at each element of Y. The error bar is a distance of E(i) above and below the curve so that each bar is symmetric and 2*E(i) long. If Y and E are a matrices, errob groups the bars produced by the elements
in each row and plots the error bars in their appropriate place above the bars.

errorb(X,Y,E) plots Y versus X with symmetric error bars 2*E(i) long. X, Y, E must be the same size. When they are vectors, each error bar is a distance of E(i) above and below the point defined by (X(i),Y(i)).

errorb(X,Y,'Parameter','Value',...) see below

% Optional Parameters
   horizontal: will plot the error bars horizontally rather than vertically
   top: plot only the top half of the error bars (or right half for horizontal)
   barwidth: the width of the little hats on the bars (default scales with the data!) barwidth is a scale factor not an absolute value.
   linewidth: the width of the lines the bars are made of (default is 2)
   points: will plot the points as well, in the same colors.
   color: specify a particular color for all the bars to be (default is black, this can be anything like 'blue' or [.5 .5 .5])
   multicolor: will plot all the bars a different color (thanks to my linespecer function)
               colormap: in the case that multicolor is specified, one
                    may also specify a particular colormap to
                    choose the colors from.
% Examples
y=rand(1,5)+1; e=rand(1,5)/4;
hold off; bar(y,'facecolor',[.8 .8 .8]); hold on;
errorb(y,e);

defining x and y
x=linspace(0,2*pi,8); y=sin(x); e=rand(1,8)/4;
hold off; plot(x,y,'k','linewidth',2); hold on;
errorb(x,y,e)

group plot:
values=abs(rand(2,3))+1; errors=rand(2,3)/1.5+0;
errorb(values,errors,'top');

% motivation for the function
It is possible to plot nice error bars on top of a bar plot with Matlab's built in error bar function by setting tons of different parameters to be various things.
This function plots what I would consider to be nice error bars as the default, with no modifications necessary.
It also plots, only the error bars, and in black. There are some very useful abilities that this function has over the matlab one.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
barweb (BARgraph With Error Bars)

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (9)
26 May 2010 Rob Campbell

Often bar charts hide useful information. The option to overlay the jittered raw data over each bar would be useful.

05 Aug 2010 Oscar

The error bars over the bar graphs are indeed simple to create and nice for publications. Would you consider fixing Matlab's bar function to allow a logarithmic vertical axis?

12 Aug 2010 Jonathan C. Lansey

It should work fine for a logarithmic vertical axis.

14 Oct 2010 Supratim Gupta

Thanks for providing this program. This is very useful. It helped me a lot to represent my data

12 Jul 2011 Andrew  
24 Jul 2011 MathMoose

Thanks, works nice, except that it adds legend entries for all the error bar lines. You should set
set(get(get(h,'Annotation'),'LegendInformation'),'IconDisplayStyle','off');
for all of the error bar plot handles.

Also, you should change the "All rights reserved" in the errorb.m comments to the BSD license.

21 Oct 2011 Jonathan C. Lansey

Thank you Math Moose! I have implemented your suggestion.

03 Nov 2011 Aakash

Really nice job!
Now I don't know where to read a changelog or anything but I had this problem that the legend wouldn't show the right colors for the line plots overlaid on the bar plot.

I just updated my errorb.m from here and it works now! Great job keeping this up to date.

Thank you.

19 Nov 2011 Aakash

suggestion:
How about being able to set transparency of the error bars? That way when I plot horizontal errorbars I can set linewidth to 50 for example, and make the error bar stretch across the whole height, set transparency to 0.5 (so I can still see my data bars).

This is useful for showing std() fro

Please login to add a comment or rating.
Updates
29 Apr 2010

The linspecer function is now included.

25 May 2010

Changed the screenshot

20 Oct 2011

I implemented the suggestions of the most eminent Math Moose.

Tag Activity for this File
Tag Applied By Date/Time
errorbars Jonathan C. Lansey 28 Apr 2010 10:07:52
error bars Jonathan C. Lansey 28 Apr 2010 10:07:52
error Jonathan C. Lansey 28 Apr 2010 10:07:52
bars Jonathan C. Lansey 28 Apr 2010 10:07:52
bar graph Jonathan C. Lansey 28 Apr 2010 10:07:52
standard error Jonathan C. Lansey 28 Apr 2010 10:07:52
standard deviation Jonathan C. Lansey 28 Apr 2010 10:07:52
graphing Jonathan C. Lansey 28 Apr 2010 10:07:52
self_rating Matt Fig 30 Apr 2010 12:19:19
confidence Jonathan C. Lansey 04 May 2010 20:42:49
statistics Jonathan C. Lansey 25 May 2010 15:04:29
bar graph Aaron 17 Jul 2010 17:14:37
bar graph Loic 02 Nov 2011 16:03:23
bars Loic 02 Nov 2011 16:03:26
error bars Loic 02 Nov 2011 16:03:31
errorbars Kun 05 Apr 2012 13:41:40

Contact us at files@mathworks.com