Code covered by the BSD License  

Highlights from
shadedErrorBar

5.0

5.0 | 8 ratings Rate this file 150 Downloads (last 30 days) File Size: 2.97 KB File ID: #26311
image thumbnail

shadedErrorBar

by Rob Campbell

 

07 Jan 2010 (Updated 18 Jan 2010)

Creates an attractive shaded error region rather than discrete bars.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

Creates a continuous shaded error region rather than discrete bars. Error region can either be specified explicitly or calculated on the fly based upon function handles. Handles of the plot objects are returned in a convenient structure.

function H=shadedErrorBar(x,y,errBar,lineProps,transparent)
                    
  Purpose
  Makes a 2-d line plot with a pretty shaded error bar made
  using patch. Error bar color is chosen automatically.
                    
  Inputs
  x - vector of x values
  y - vector of y values or a matrix of n observations by m cases
      where m has length(x);
  errBar - if a vector we draw symmetric errorbars. If it has a
           size of [2,length(x)] then we draw asymmetric error bars
           with row 1 being the upper bar and row 2 being the lower
           bar. ** alternatively ** errBar can be a cellArray of
           two function handles. The first defines which statistic
           the line should be and the second defines the error
           bar.
  lineProps - [optional,'-k' by default] defines the properties of
              the data line. e.g.:
              'or-', or {'-or','markerfacecolor',[1,0.2,0.2]}
  transparent - [optional, 0 by default] if ==1 the shaded error
                bar is made transparent, which forces the renderer
                to be openGl. This means that saved .eps files
                won't look so good because they'll be rasters not
                vectors.

  Outputs
  H - a structure of handles to the generated plot objects.

  Examples
  y=randn(30,80); x=1:size(y,2);
  shadedErrorBar(x,mean(y,1),std(y),'g');
  shadedErrorBar(x,y,{@median,@std},{'r-o','markerfacecolor','r'});

  Overlay two transparent lines
  y=randn(30,80)*10; x=(1:size(y,2))-40;
  shadedErrorBar(x,y,{@mean,@std},'-r',1);
  hold on
  y=ones(30,1)*x; y=y+0.06*y.^2+randn(size(y))*10;
  shadedErrorBar(x,y,{@mean,@std},'-b',1);

  Rob Campbell - November 2009

Acknowledgements

This file inspired Plotter For Psd Objects, Boundedline: Line Plots With Shaded Error/Confidence Intervals, and Mean Square Displacement Analysis Of Particles Trajectories.

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File  
Everyone's Tags
confidence interval(7), error bar(2), pick of the week, plot(2), potw
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (9)
20 Feb 2013 cpas1940  
08 Feb 2013 uncung fgv

what is shade error bar? i try to execute it but cannot.

27 Jan 2013 Wantong  
07 Aug 2012 Diego  
10 Jul 2012 Franklin  
29 May 2012 German Gomez-Herrero  
02 Mar 2012 Agatha lenartowicz

Very helpful function. Thanks!

12 Apr 2011 Estella Liu  
07 Mar 2010 TIAN ZHOU  
Updates
12 Jan 2010

Correct bug that caused patch area not to be plotted when y contained NaNs and error bars were generated using the function handles approach.

18 Jan 2010

Improved error-checking of input args and revised some of the comments.

Contact us