errorbar

Plots data with error bars.

Category: Graphics > 2-D and 3-D Plots

Syntax

errorbar(x, y, err)

Plots y against x with symmetric vertical error bars of length err above and below each point.

errorbar(x, y, neg, pos)

Uses separate lengths below (neg) and above (pos).

errorbar(x, y, yneg, ypos, xneg, xpos)

Adds horizontal error bars too.

errorbar(___, Name, Value)

Sets properties such as 'Marker', 'LineWidth' or 'CapSize'.

e = errorbar(___)

Also returns the ErrorBar object.

Description

Error bars show the uncertainty of a measurement: a standard deviation, a confidence interval or a tolerance. The line connects the data points, and each point has a vertical segment with a cap at each end.

Input arguments

x, y
Vectors of the same length with the data points.
err
Error lengths, one per point; the bar spans y - err to y + err.
'CapSize'
Width of the end caps in points.

Output arguments

e
The ErrorBar object.

Example

Measurements with uncertainty

x = 1:5;
y = [2.1 3.9 6.2 7.8 10.1];
err = [0.3 0.4 0.2 0.5 0.3];
e = errorbar(x, y, err, 'Marker', 'o');
disp(e.CapSize)
xlim([0 6])
Output
     6

Notes

The direction options 'horizontal' and 'both' are not supported and raise an error; 'vertical' is accepted.

See also

plot bar scatter std fill