Code covered by the BSD License  

Highlights from
Adjust error bar width

4.9 | 21 ratings Rate this file 150 Downloads (last 30 days) File Size: 1.86 KB File ID: #22826
image thumbnail

Adjust error bar width


Arnaud Laurent


29 Jan 2009 (Updated )

Adjust error bars width in an errorbar plot to a ratio of the x-axis or a length (x-axis units).

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information

function errorbar_tick(h,w,xtype)
ERRORBAR_TICK Adjust the width of errorbars

ERRORBAR_TICK(H) adjust the width of error bars with handle H. Error bars width is given as a ratio of X axis lenght (1/80).

ERRORBAR_TICK(H,W) adjust the width of error bars with handle H. The input W is given as a ratio of X axis lenght (1/W). The result is independant of the x-axis units. A ratio between 20 and 80 is usually fine.

ERRORBAR_TICK(H,W,'UNITS') adjust the width of error bars with handle H. The input W is given in the units of the curent x-axis.


This file inspired Set Errorbar Width And Thickness, Update Error Bar Widths Automatically On Figure Resize, Eb Ticklength, and Grouped Bar Plots With Error Bars.

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (28)
27 Dec 2014 Tobia vendrametto

Tobia vendrametto

It seems a great and useful function, but it is not working with 2014b version.

x = get(hh(2),'xdata');

hh = [ ] and so the error. But I cannot solve it. =(
Can someone?


Comment only
21 Nov 2014 Adam


Always loved this function, but seems to be broken by 2014b :-(

10 Nov 2014 John Trimper

John Trimper

I've used/loved this function for years, but something's going wrong for me tonight. Also the first time I've used it with MatLab 2014b (64bit).

With x values of [1:4], errorbar_tick is moving my 4th point over to an x-value of .08, so the updated series of x values becomes [1 2 3 .08]. I'm totally boggled. Any ideas?

04 Nov 2014 Cengiz Gunay

Cengiz Gunay


28 Oct 2014 Josef Pörnbachr

Josef Pörnbachr

17 Jul 2014 Arnab Banerjee

Arnab Banerjee

Works great. For a graph with many errorbar plots this works:
>> h = get(gca,'Children');
>> % h is an array of plot handles
>> errorbar_tick(h(n),200); % etc.

21 Nov 2013 Dan


Works great for my linear axis. Thanks for sharing.

12 May 2013 LDELBENE


What about if the x axis is in log scale?

Comment only
08 Feb 2013 J


This function is really helpful!

Note that if you simply find and replace "x" with "y" throughout the code, it then works on horizontal error bars generated by, for example, errorbar_x.


15 Oct 2012 Emily


15 Aug 2012 Amanda Whitmire

Amanda Whitmire

I really like this function, but I wish it also worked on horizontal error bars (FEX function herrorbar). Otherwise, this is very handy.

03 Jul 2012 Min Liu

Min Liu

Solved my long-standing problem. Thank you~

26 Mar 2012 James Herman

James Herman

21 Nov 2011 Felipe G. Nievinski

Felipe G. Nievinski

You might want to insert this at line # 39:

if ~isscalar(h)
arrayfun(@(h) errorbar_tick(h,w,xtype), h);

Comment only
15 Nov 2011 Felipe G. Nievinski

Felipe G. Nievinski

It's great that this function operates on the handle output by the errorbar function, rather than duplicating what the errorbar function already does.

30 Aug 2011 Frank Coumans

Frank Coumans

27 Jul 2011 Tom Etzer

Tom Etzer

26 Mar 2011 Lin Li

Lin Li

27 Jul 2010 Anton Daneyko

Anton Daneyko

06 Jul 2010 Tim DuBois

Tim DuBois

11 Jun 2010 Tobias


Thanks for sharing your solution! It works fine as long as I one have one error bar series in a plot but I can't get it to work when I have more (as in> errorbar, hold on, errorbar). Do you have a fix for this?

Comment only
14 Feb 2010 Max


Works great! Thanks a lot!

13 Dec 2009 alex m

alex m

good idea, but I'm new to matlab and am unsure of the variables h and xtype, could someone post an example?

Comment only
08 Oct 2009 Dan Knudsen

Dan Knudsen

Thanks very much! Easy to use and works great.

One quick tip, which is relatively obvious but might be nice to add to the help: If you'd like to get rid of the ticks entirely, it's as easy as calling: errorbar_tick(h,0,'units')

14 Aug 2009 Arnaud Laurent

Arnaud Laurent

Re: thanks for your input Sathish, you're right the script wasn't made for log scale. I'll update the file to take care of that.

Comment only
31 Jul 2009 Sathish Krishnan

Sathish Krishnan

cool job!! but the feature does not retain when I change linear scale to log scale(i.e. the width is wider in log scale and is uncontrollable)

04 Jun 2009 Joey Doll

Joey Doll

18 Mar 2009 Moritz


Nice work! This has driven me crazy in the past, but not any more .

Comment only
02 Feb 2009

Header updated with examples, screenshot provided

02 Feb 2009

Screenshot updated

06 Feb 2009

The function has been updated to enable the use of a length as an input.
A new screenshot was made.

Contact us