Code covered by the BSD License  

Highlights from


5.0 | 15 ratings Rate this file 151 Downloads (last 30 days) File Size: 5.86 KB File ID: #22216
image thumbnail




23 Nov 2008 (Updated )

plots data with x and/or y error bars and supports logarithmic scaling for both axes.

| Watch this File

File Information

ploterr is a universal tool for plotting data with error bars. The following features are supported:

- linear/logarithmic scaling
- x and/or y error bars
- relative/absolute errors
- width of bar handles adjustable

Basically it unifies the features of errorbarxy, errorbarloglog, errorbar_x and errorbar in one single program.

For a detailed description and examples see the documentation in the file.

The technique for plotting the error bars is adapted from MATLAB's v6 errorbar, which is also used by Goetz Huesken's errorbar_x. With this technique the x error bars as well as the y error bars are one big line object, in contrast to errorbarloglog where each single error bar consists of three separate lines. That prevents an overflow of the legend with lots of separate line objects and makes it a lot easier to change the line style of the error bars.


Errorbar X inspired this file.

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (27)
04 Apr 2014 Nitsan

Thank you for this file!

I also wanted to ask you, is there a way to integrate those x-y errors with cftool or at least some kind of fitting that takes the errors into account?
I failed to find useful information online.

Thanks again,

11 Jun 2012 Brian

Great file! Very helpful. Thank you!

30 May 2012 Alex Carisey  
02 May 2011 James Hickey

Is there a way to change the width/length of the 'T' marks at the end of the errorbars?

19 Jan 2011 Jiaxin Han  
31 Dec 2010 Eddie

Hi Felix,
Here's a small mistake catching mechanism that can be added:
I'm using ploterr with the toggle for 'logxy' on, and I didn't realize that there were some points that would be negative with error bars, and I tried plotting them, and ploterr "did" without returning any error. I thought the plot looked a little sparse, and I couldn't figure it out until I finally noticed these tiny pixels on my graph. I'm not quite sure what they are because I haven't looked into ploterr, but it seems that feeding points where data-error<=0 (I tried 0 as well), makes ploterr plot these tiny pixels on your graph instead of the real points you wanted. They're very hard to see, and I missed them the first dozen time I look at my graph; so, it may be handy to provide some kind of error message when that happens.

14 Nov 2010 Nitay Megides

I'd like to report a bug:
When using several plots with ploterr, the legend acts a bit funny:
1. The colors of the different plots is the same as the first plot (only in the legend)
2. The plot order is reversed

14 Nov 2010 Nitay Megides

Another issue with the legend: The plots order is reversed

31 Jul 2010 Boris

Hi, can someone give an example how more then 1 line can be plotted together?
for example: x = 0:15;
x1 = 5:20;
x2 = 10:25;
y =exp(-x).*(rand(1,16)*0.9+0.1);

I could not figure out how to do it by ploterr([x1 x2 ... xn],[y1 y2 ... yn],....) so I tried it the way as below, but can not get the legend of all entries.

h =ploterr(x,y,0.3,{exp(-x)*0.1 exp(-x)},'r.','logx','hhxy',0.5)
set(h(2),'Color','b'), set(h(3),'Color','b')
hold all;
h =ploterr(x1,y1,0.4,{exp(-x)*0.2 exp(-x)},'k.','logx','hhxy',0.4)
set(h(2),'Color','k'), set(h(2),'Color','k')
h =ploterr(x2,y2,0.5,{exp(-x)*0.3 exp(-x)},'b.','logx','hhxy',0.3)
set(h(2),'Color','r'), set(h(3),'Color','r')
legend(h,{'data' 'error x' 'error y'})



29 Mar 2010 TIAN ZHOU  
11 Feb 2010 Abhinand Jha

How can i change the width of the horizontal errorbars?

15 Jan 2010 Nicholas Valles

Thank you for this file, it does just what I want it too.

04 Jul 2009 Ken

Thank you, Felix, for this excellent function! Erik Benkler (who posted above) is right: ploterr really is the Swiss Army Knife of error bar plots.

29 Apr 2009 Anna Avdeeva  
29 Apr 2009 Anna Avdeeva

I have read your comment, that function can handle more than one plot, using
ploterr([x1 x2 ... xn],[y1 y2 ... yn],....) .
However I am having difficulties with plotting two curves using two user set styles ('^r','logxy' and 'ob','logxy').
Could you please let me know how to solve this?

Thank you in advance,

13 Mar 2009 Erik Benkler

this is the swiss army knife for errorbar plots. Earlier, I have made a similar submission on file exchange, but I recommend to use ploterr.m

17 Feb 2009 Felix Zoergiebel

1. The function can handle more than one plot, however the syntax you proposed is not supported. If all data is of the same length, you can plot several graphs at one time with
ploterr([x1 x2 ... xn],[y1 y2 ... yn],....)
Each column will plot to one line. See the help for details. (doc ploterr)
If you want to plot several lines with different numbers of data points, plot them one after the other:
for i=1:n, ploterr(x{i},y{i},xerr{i},yerr{i}), hold all, end

2. The nomenclature works fine for me. erry makes "vertical" error bars, errx makes "horizontal" error bars.


17 Feb 2009 cabrego

Can this function handle more than one plot?

e.g., ploterr(x1,y1,errx1,errx2,x2,y2,errx2,erry2...)

Also I think the nomenclature is backwards:

e.g. ploterr(x1,y1,erry1,errx1) is how it really works.

01 Feb 2009 Madhusudhan  
16 Jan 2009 Daniel Hauser

thx, it everything works really fine, your m-file helps me alot with my analyses!


16 Jan 2009 Daniel Hauser  
15 Jan 2009 Felix Zoergiebel

I do not really understand what you want to do, but I guess it's either of the following:
If you want to have errorbars on each of the interpolated points, do


If you want the interpolated points plotted as a line and only the "raw data" as points with errorbars, you can do that with two consecutive plot commands:

hold on, plot(x1,y1), hold off

Hope that helps,

15 Jan 2009 Daniel Hauser

hi, first of all, your programm is great!!! but is it possible to add your errorbars to an interpolated function:


with error: xerr=0.02, yerr=0.5

thx daniel

29 Dec 2008 Sergei

with the bugfix it works fine

15 Dec 2008 Felix Zoergiebel

The bugfix is online, I am looking forward to your comments!

13 Dec 2008 Felix Zoergiebel

I'm sorry about that. I forgot to test the last update for use with no options. Here's a fix you can use until the new version is online:

Add those to lines to the beginning of the getproperties function:

function [sym,lx,ly,hx,hy] = getproperties(A)
lx=0; ly=0; hx=2/3; hy=2/3; sym='-'; % presets
if isempty(A), return, end

13 Dec 2008 Sergei

>> x = 2:11;
>> y = sin(x);
>> e = std(y)*ones(size(x));
>> ploterr(x,y,e)

??? Index exceeds matrix dimensions.

Error in ==> ploterr>getproperties at 318

Error in ==> ploterr at 136

03 Dec 2008

Changed the user interface. Handle sizes and logarithmic scaling can now be set via properties. Passing LineSpec is not compulsory anymore when manually setting logscale or handle sizes.

13 Dec 2008

Bugfix. It is now possible to use no options.

14 Feb 2009

Added properties hhabsx, hhabsy and hhabsxy: Set the handle size to an absolute value rather than a fraction of the mean distance of the datapoints.

Contact us