version 1.3.0.0 (5.86 KB) by
Felix Zoergiebel

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

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.

Felix Zoergiebel (2021). ploterr (https://www.mathworks.com/matlabcentral/fileexchange/22216-ploterr), MATLAB Central File Exchange. Retrieved .

Created with
R2007a

Compatible with any release

- Graphics > 2-D and 3-D Plots > Line Plots > Errorbars >

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!Create scripts with code, output, and formatted text in a single executable document.

Matthew StyslingerSARA ALAOUI-SOSSERick AdamsHONG FATT CHONGTHANKS! Helped a lot

Mohammad HeriyantoWilliam BarnesVery 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.

Presper EckertExcellent functionality and very useful!

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

Nitsan.

BrianGreat file! Very helpful. Thank you!

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

Jiaxin HanEddieHi 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 MegidesI'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 MegidesAnother issue with the legend: The plots order is reversed

BorisHi, 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);

y1=exp(-x).*(rand(1,16)*0.7+0.3);

y2=exp(-x).*(rand(1,16)*0.2+0.5);

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

Thanks.

Boris

EMC_solverAbhinand JhaHow can i change the width of the horizontal errorbars?

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

KenThank 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 AvdeevaAnna AvdeevaI 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,

Anna

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

Felix Zoergiebel1. 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.

Felix

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

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

daniel

Daniel HauserFelix ZoergiebelI 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

ploterr(x1,y1,0.02,0.5).

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:

ploterr(phi1,Iphi1,0.02,0.5,'o')

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

Hope that helps,

Felix

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

eg:

phi1=[-2,-1,-0.5,0,1,1.5,2,3];

Iphi1=[0,20,120,180,170,115,50,0];

x1=-2:0.01:3;

y1=interp1(phi1,Iphi1,x1,'cubic');

with error: xerr=0.02, yerr=0.5

thx daniel

Sergeiwith the bugfix it works fine

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

Felix ZoergiebelI'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>> 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

[k,k,k,errmsg]=colstyle(A{1});

Error in ==> ploterr at 136

[symbol,logx,logy,hhx,hhy]=getproperties(varargin);