Code covered by the BSD License  

Highlights from
Create Healthy Looking Error Bars

5.0

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

Create Healthy Looking Error Bars

by

 

27 Apr 2010 (Updated )

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

Barweb (Ba Rgraph With Error Bars) inspired this file.

This file inspired Grouped Bar Plots With Error Bars.

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (10)
27 May 2014 Katie  
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

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.

21 Oct 2011 Jonathan C. Lansey

Thank you Math Moose! I have implemented your suggestion.

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.

12 Jul 2011 Andrew  
14 Oct 2010 Supratim Gupta

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

12 Aug 2010 Jonathan C. Lansey

It should work fine for a logarithmic vertical axis.

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?

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.

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.

Contact us