image thumbnail

Plot data with error bars on both x and y axes

version 1.81.0.0 (3.58 KB) by Qi An
plot data with error bars along both x and y axes

13.2K Downloads

Updated 07 Jan 2016

View License

ERRORBARXY is a function to generate errorbars on both x and y axes
with specified errors modified from codes written by Nils Sjöberg
(http://www.mathworks.com/matlabcentral/fileexchange/5444-xyerrorbar)
errorbarxy(x, y, lerrx, uerrx, lerry, uerry) plots the data with errorbars on both
x and y axes with error bars [x-lerrx, x+uerrx] and [y-lerry, y+uerry]. If there is
no error on one axis, set corresponding lower and upper bounds to [].
errorbarxy(x, y, errx, erry) plots the data with errorbars on both x and
y axes with error bars [x-errx, x+errx] and [y-erry, y+erry]. If there
is no error on one axis, set corresponding errors to [].
errorbarxy(..., S) plots data as well as errorbars using specified
character strings. S is a cell array of 3 element, {sData, cEBx, cEBy},
where sData specifies the format of main plot, cEBx specifies the
color of errorbars along x axis and cEBy specifies the color of
errorbars along y axis.
errorbarxy(AX,...) plots into AX instead of GCA.

H = errorbar(...) returns a vector of errorbarseries handles in H,
within which the first element is the handle to the main data plot and
the remaining elements are handles to the rest errorbars.
H is organized as follows:
H.hMain is the handle of the main plot
H.hErrorbar is a Nx6 matrix containing handles for all error bar lines,
where N is the number of samples. For each sample, 6
errorbar handles are saved in such an order:
[Horizontal bar, H bar left cap, H bar right cap,
Vertical bar, V bar lower cap, V bar upper cap]
For example
x = 1:10;
xe = 0.5*ones(size(x));
y = sin(x);
ye = std(y)*ones(size(x));
H=errorbarxy(x,y,xe,ye,{'ko-', 'b', 'r'});
draws symmetric error bars on both x and y axes.
NOTE: errorbars are excluded from legend display. If you need to
include errorbars in legend display, do the followings:
H=errorbarxy(...);
arrayfun(@(d) set(get(get(d,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','on'), H(2:end)); % include errorbars
hEB=hggroup;
set(H(2:end),'Parent',hEB);
set(get(get(hEB,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','on'); % include errorbars in legend as a group.
legend('Main plot', 'Error bars');

Developed under Matlab version 7.10.0.499 (R2010a)
Created by Qi An
anqi2000@gmail.com

Cite As

Qi An (2021). Plot data with error bars on both x and y axes (https://www.mathworks.com/matlabcentral/fileexchange/40221-plot-data-with-error-bars-on-both-x-and-y-axes), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!