Code covered by the BSD License  

Highlights from
HERRORBAR

4.57143

4.6 | 28 ratings Rate this file 319 Downloads (last 30 days) File Size: 2.55 KB File ID: #3963
image thumbnail

HERRORBAR

by Jos (10584)

 

16 Sep 2003 (Updated 07 Aug 2006)

Horizontal errorbar plot.

| Watch this File

File Information
Description

HERRORBAR Horizontal Error bar plot.
   HERRORBAR(X,Y,L,R) plots the graph of vector X vs. vector Y with horizontal error bars specified by the vectors L and R. L and R contain the left and right error ranges for each point in X. Each error bar is L(i) + R(i) long and is drawn a distance of L(i) to the right and R(i) to the right the points in (X,Y). The vectors X,Y,L and R must all be the same length. If X,Y,L and R are matrices then each column produces a separate line.
 
   HERRORBAR(X,Y,E) or HERRORBAR(Y,E) plots X with error bars [X-E X+E].
   HERRORBAR(...,'LineSpec') uses the color and linestyle specified by the string 'LineSpec'. See PLOT for possibilities.
   
   Example:
      x = 1:10;
      y = sin(x);
      e = std(y)*ones(size(x));
      herrorbar(x,y,e)

History notice:
This code was originally posted to the newsgroup, comp.soft-sys.matlab, by me. In 2003 Greg Aloe (The MathWorks) rightfully decided to take ownership, after several unsuccesfull attempts to contact me, and put it on the FEX so that others could benefit from it.
In 2006 I contacted Greg Aloe and we decided to return ownership to me.
I like to thank him for his efforts. Jos

Acknowledgements
This submission has inspired the following:
errorbar_x
MATLAB release MATLAB 6.5 (R13)
Other requirements This function should work with at least MATLAB 5.2 (R10) and later.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (43)
25 Oct 2003 David Koski  
28 Oct 2003 Troy Goodson

I looked at a few of the errorbar functions here. I really like that this is based on the included errorbar.m function as I don't have to learn new input arguments. The only things I think are missing are

- an option to do both horizontal and vertical error bars.

- an option to change the size of the tees on the error bars (MathWorks' errorbar.m doesn't have this, either)

06 Jan 2004 david wang

very good, you can use
errorbar(x,y,ex);
hold on;
herrorbar(x,y,ey);
to have both horizontal and verical error bars created.

28 Jan 2004 Stefan Schlamp  
26 Apr 2004 Bob Wood

good.
works like errorbar.

22 Nov 2004 Jonathan Ashmore

its great, worked first time, thanx heaps, has saved me a whole lot of hassle

29 Nov 2004 Rem Z

Not robust to log axes.

12 Jan 2005 Boh Ruffin  
14 Feb 2005 Carlos Vargas

Right waht I need, it also saved me a lot of trouble.

22 Feb 2005 Ted R

This function works exactly as advertised. Use it!

18 May 2005 Rebecca Vislay-Meltzer

This rocks!! Use it with errorbar to plot both x and y error bars. I've had issues with "errorbarxy" function.

24 May 2005 Josh F

Good stuff. You saved my thesis.

25 Jul 2005 Eugene Tan

Would like to recommend a change in the code

tee = (max(x(:))-min(x(:)))/100;

changed to using some average of the given error:

tee = mean([u; l])/3;

This will then accomodate single points with errors. You can do the same in the for Matlab's "errorbar" function.

15 Sep 2005 C L

excellent. i have been trying to do this for ages. thankyou.

23 Sep 2005 David Swa

Nice job, this is a very useful tool. Dont forget you can overlay graphs to get both x and y errorbars.

06 Jun 2006 B L

Very good. Thanks

20 Jun 2006 Nadya V

Good job! Thank you.

18 Aug 2006 Steven Shimizu

very good, except you can't just enter the value of the error, (i.e. herrorbar(x,y,0.1), unlike with errorbar. Instead, you have to create a vector of all the same values.

23 Aug 2006 Jos vdG

To Steven Shimizu:
thanks for your rating. This submission is based on the errorbar function in R10, which does not expand scalar inputs. This feature has only been introduced in more recent releases (>R13).

31 Aug 2006 Seth G.

Works as described

21 Sep 2006 David Sterling

Nice work. Currently won't put an error bar on a single point though... How about changing line 103 to be something like:

tee = max(0.01, (max(y(:))-min(y(:)))/100);

so that there is a default tee height for single points. More generally you might set default tee height to some function of Ylim so error bars show up no matter the Y scale.

28 Sep 2006 Anindo Roy

Great code. I had a question: is there any MATLAB code out there which allows one to errorbars on a bar plot (like Excel does)?
Thanks in advance for your suggestions.

05 Mar 2007 Josh Hanson

Nice. Thank you

16 Nov 2007 S I  
01 Sep 2008 Aniruddha Sengupta

Certain specifications, such as 'LineWidth', don't seem to work with "herrorbar" but work perfectly with "errorbar".

10 Sep 2008 Jos (the author)

Dear Aniruddha Sengupta, these incongruencies between errorbar and herrorbar are most likely due to version differences.

19 Oct 2008 philippe chassot  
21 Nov 2008 Kim Hansen

PLEASE PLEASE Help

I am almost about to give up. How do I remove those crappy connection lines that herrorbar produces. In the normal errorbar i can just write

errorbar(x,y,e,'LineStyle','none')

where e offcourse is the error on the y values which in my case should be added to the x values. So I really want the command to be like this

herrorbar(x,y,e,'LineStyle','none')

but that does not work.
Please help

05 May 2009 Jordan

How do I put vertical end markers on my horizontal error bars? The code worked great to put them in but I have data points that overlap substantially so I need end markers to show their bounds.

thanks

09 Dec 2009 Andrew Stephenson

How do I go about changing the colour to something other than the default 'k, r, g, b' values? When using the errorbar command I can simply type

erroarbar(x,y,ex,'.', 'color',[0.5, 0.7, 1])

but this doesn't work when using herrorbar.
Any help would be greatly appreciated.

Thanks

10 Dec 2009 Jos (10584)

@Jordan, @ Andrew
Note that HERRORBAR is based on errorbar R13. As a work around you can get the handle:

   h = herrorbar(x,y,ex) ;

and modify its properties using SET. For instance,

  set(h,'color',[0.5 0.7 1])

28 Jan 2010 J B

great, but can one change 'linewidth'?...or shall i give up trying!

29 Jan 2010 Jos (10584)

@ J B. Please see my comment of 10 dec 2009:

h = errorbar(x,y,ex) ;
set(h,'linewidth',2)

21 Apr 2010 J B

Has anyone had any success when using the herrorbar function of plotting thin errorbars (i.e. linewidth = 1) yet with a thick line (i.e. linewidth =2) conecting plotted points?

21 Apr 2010 Jos (10584)

@ J B
You can modify the two handles returned by herrorbar separately, as in:

h = errorbar(x,y,ex) ;
set(h(1),'color','r') ;
set(h(2),'linewidth',2) ;

23 Apr 2010 J B  
26 Apr 2010 Shirley

It works great, but I have one question: How can I get bigger end markers?

19 Oct 2010 Juha

Messes legend if you use different markers and legend. Try this example and you'll know what I mean:

herrorbar(22, 20, 2.74, 'o')
hold on;
herrorbar(21, 26, 2.63, 'p')
legend('test1', 'test2')

20 Oct 2010 Jos (10584)

@Juha, it is ill-advised to use legend that way. Better get the indices of the plots and use them to create a proper legend.
Also note that this function was written for ML13, and therefore returns 2 handles instead of 1. Use this to your advantage!

h1 = herrorbar(22, 20, 2.74, 'o')
hold on;
h2 = herrorbar(21, 26, 2.63, 'p')
legend([h1(2) h2(2) h2(1)],{'test1', 'test2','error of test2'})

04 Mar 2011 Dan

Nicely done - though I concur with previous problems concerning the height of tee for single points (or multiple points at the same y-value). My work around was to allow y to be longer than x, then clip y to y([1 : length(x)]), but this won't work for non-vector input.

12 Mar 2011 Carlos

To remove the connecting lines just change
line 148 of the mfile to:
h = [h;plot(x,y,symbol,'LineStyle','none')];

12 Mar 2011 Jos (10584)

@Carlos, to avoid modifying the file, you can easily change the linestyles afterwards:
h = herrorbar(...) ;
set(h(2), 'linestyle', 'none') ;

28 Mar 2011 Gerry  
Please login to add a comment or rating.
Updates
07 Aug 2006

changed ownership

Tag Activity for this File
Tag Applied By Date/Time
specialized Jos (10584) 22 Oct 2008 07:07:38
plotting Jos (10584) 22 Oct 2008 07:07:38
horizontal Jos (10584) 22 Oct 2008 07:07:38
error bar Jos (10584) 22 Oct 2008 07:07:38
graphics Jos (10584) 22 Oct 2008 07:07:38
x Jos (10584) 22 Oct 2008 07:07:38
errorbar Jos (10584) 22 Oct 2008 07:07:38
errorbar Michael Ertl 12 May 2011 08:58:24
horizontal Jose Ercolino 13 Jun 2011 19:49:10
error bar Jose Ercolino 13 Jun 2011 19:49:17
errorbar Jose Ercolino 13 Jun 2011 19:49:18
graphics Jose Ercolino 13 Jun 2011 19:49:19
error Jose Ercolino 13 Jun 2011 19:49:20
plot Jose Ercolino 13 Jun 2011 19:49:20
errorbar Xin 05 Jul 2011 17:06:56
error foxkingdom 08 Jan 2012 14:01:01

Contact us at files@mathworks.com