File Exchange

image thumbnail


version 1.3 (5.86 KB) by

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



View License

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.

Comments and Ratings (30)

Very useful but.... Is it possible to use a log10 rather than log (i.e. to use log base 10 rather than log base e) for the axes. For example, I tried log10x instead of log, but no joy.

Excellent functionality and very useful!


Nitsan (view profile)

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,


Brian (view profile)

Great file! Very helpful. Thank you!

Alex Carisey

James Hickey

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

Jiaxin Han


Eddie (view profile)

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.

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

Nitay Megides

Another issue with the legend: The plots order is reversed


Boris (view profile)

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'})




TIAN ZHOU (view profile)

Abhinand Jha

How can i change the width of the horizontal errorbars?

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


Ken (view profile)

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.

Anna Avdeeva

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,

Erik Benkler

Erik Benkler (view profile)

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

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.



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.


Daniel Hauser

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


Daniel Hauser

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,

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


Sergei (view profile)

with the bugfix it works fine

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

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


Sergei (view profile)

>> 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



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.


Bugfix. It is now possible to use no options.


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.

MATLAB Release
MATLAB 7.4 (R2007a)

Inspired by: errorbar_x

Inspired: errbar, errorbarxy, superbar

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video