errorbar — Create plots with symmetric or asymmetric error bars using MATLAB-compatible errorbar forms.
errorbar visualizes uncertainty using vertical error bars with symmetric or asymmetric magnitudes. It returns graphics handles and follows MATLAB-compatible argument and property forms.
Syntax
h = errorbar(Y, E)
h = errorbar(X, Y, E)
h = errorbar(X, Y, YNeg, YPos)
h = errorbar(X, Y, YNeg, YPos, XNeg, XPos)
h = errorbar(ax, ...)Inputs
Y- Type
NumericArray- Required
- Yes
- Description
- Data values.
E- Type
NumericArray- Required
- Yes
- Description
- Symmetric Y error magnitudes.
X- Type
NumericArray- Required
- Yes
- Description
- X coordinates.
Y- Type
NumericArray- Required
- Yes
- Description
- Y coordinates.
YNeg- Type
NumericArray- Required
- Yes
- Description
- Negative Y error magnitudes.
YPos- Type
NumericArray- Required
- Yes
- Description
- Positive Y error magnitudes.
XNeg- Type
NumericArray- Required
- Yes
- Description
- Negative X error magnitudes.
XPos- Type
NumericArray- Required
- Yes
- Description
- Positive X error magnitudes.
ax- Type
NumericScalar- Required
- Yes
- Description
- Target axes handle.
data- Type
Any- Required
- Variadic
- Description
- Errorbar positional data arguments.
props- Type
Any- Required
- Variadic
- Description
- Style and name/value properties.
Returns
h- Type
NumericScalar- Description
- Handle to the created error bar series.
Errors
RunMat:errorbar:InvalidArgument- When
- Input vectors, error vectors, style arguments, or axes-target forms are malformed.
- Message
errorbar: invalid argument
RunMat:errorbar:Internal- When
- Internal render preparation or GPU vertex generation fails.
- Message
errorbar: internal operation failed
RunMat:plotting:TooManyOutputs- When
- More than one output is requested from a coordinate chart constructor.
- Message
plotting: too many output arguments
Behavior
Vertical, horizontal, and both-direction error-bar forms are supported through the runtime and replay/render stack.
Vector inputs create one error-bar handle. Matrix inputs create one registered error-bar series per plotted line; returning the complete handle vector remains limited by the current scalar graphics-handle builtin ABI.
All eight integer classes and logical coordinate/error arrays are accepted and cross one deliberate floating client-graphics boundary.
Cap size, line styling, marker appearance, display names, and related properties use the shared plotting object/property system.
Error bars remain subplot-local and integrate naturally with legends and axes state.
GPU-backed geometry is used only for compatible real floating vectors; integer, logical, matrix, and unsupported combinations gather to client plotting while preserving the same visible result.
Datetime, duration, categorical, distributed-array, and complete ErrorBar data-property compatibility remain development gaps.
Rendering and residency
errorbar accepts resident floating inputs. Documented integer and logical inputs gather through their owning provider before the explicit client graphics conversion boundary; supported floating-vector combinations can use RunMat's direct geometry path.
Real floating vectors can remain resident through RunMat's direct geometry path. Integer and logical buffers gather authoritatively before the client graphics conversion and are never reinterpreted as floating buffers.
Dedicated GPU geometry generation covers supported real floating-vector workflows; MATLAB documents errorbar gpuArray execution as client-side.
Markers continue to use the shared marker path so line/marker styling stays consistent with the rest of the plotting stack.
Direct floating rendering precisions
single
double
Coordinate broadcasting
none
Runtime contract and boundaries
The result is a host graphics handle, not a numeric coordinate array. Coordinate parsing, native source storage, series expansion, style validation and graphics state use the existing plotting owners. Numeric handle aliases are resolved at Runtime, so static inference does not guess that a scalar coordinate denotes axes. The line, bar, barh and area constructors may return a row of handles; the other identities return the first created handle. More than one language output is rejected before chart work.
Single and double source data use their native storage where the chart has typed source properties; all eight integer classes use the declared identity-specific coordinate/control rules. Rendering is an explicit floating geometry boundary. In particular errorbar, bar, barh and area convert client graphics data to floating geometry; this does not certify exact integer-valued rendered pixels. Complex, logical, sparse, empty and matrix admission is decided by each existing numerical/shape parser, not by this shared ingress. Unsupported representations raise the existing parser diagnostic rather than being assumed fully MATLAB compatible.
Direct GPU rendering is conditional on the actual owning provider, live physical input leases, floating class/storage, supported shape/style, compatible shared device exports and native plotting feature availability. A pre-effect unavailable direct route may take the existing client path; a failed or partially completed export/reduction/emission is terminal and never permission to replay on the host. Source-property reads and figure persistence can perform later explicit readback. There is no elementwise/reduction fusion, distributed execution or portable numeric provider kernel for these graphics sinks.
User-interface capability and host-callback effects describe graphics creation/presentation, not numeric purity. Portable Runtime linking and an ordinary execution stack allow Native and Wasm ingress; actual presentation requires the installed graphics host. Retained chart data, style metadata, renderer buffers and serialization are separate lifetimes. Current chart scratch/state has no complete finite allocation owner: Managed policy is rejected before argument extraction, gather or chart mutation through the existing HostAllocationReceipt authority. Ordinary Unbounded resident and host routes remain available. Issuer/policy/cancellation are fenced before publication and errors carry Never replay. This refusal, unbounded host loops, provider/renderer-private allocations, full property parity and measured performance remain open obligations; Incomplete/Partial is not a completion certificate.
Supported representations and remaining forms
Real single/double and all native integer classes are accepted; logical arrays are explicitly converted to double client coordinates and complex coordinate/error inputs are rejected. Dense vector or matrix layouts select one series per supported row/column orientation. Empty/mismatched inputs, invalid magnitudes, malformed styles and missing required data use existing validation diagnostics. Scalar error lengths are broadcast by the existing layout owner, not an elementwise provider kernel.
Two-, three-, four- and six-data parsing distinguishes y-only, symmetric/asymmetric explicit coordinates and independent X/Y deviations; horizontal and both orientation flags, CapSize, LineSpec, markers, Color, LineWidth, LineStyle and DisplayName use the existing ErrorBar style owner. Selected integer/single values convert once per selected element to f64 client graphics. Matrix calls publish every series but the current builtin returns only the first handle. ErrorBar data-property read/mutation parity is incomplete: the current getter exposes Type, Parent, Children and style fields, not complete coordinate/deviation properties.
Examples
Plot symmetric vertical error bars
x = 1:5;
y = [2 3 2.5 4 3.5];
err = [0.2 0.3 0.1 0.4 0.2];
errorbar(x, y, err, err);Plot asymmetric both-direction error bars
x = 1:4;
y = [3 4 2 5];
xn = [0.1 0.2 0.1 0.3];
xp = [0.2 0.3 0.2 0.4];
yn = [0.3 0.2 0.4 0.2];
yp = [0.4 0.3 0.5 0.3];
errorbar(x, y, yn, yp, xn, xp);Style an error-bar object and label it for the legend
x = 1:5;
y = [1 2 1.5 3 2.5];
h = errorbar(x, y, 0.2*ones(size(x)), 0.2*ones(size(x)));
set(h, 'LineWidth', 2, 'DisplayName', 'measurement');
legend;Measurements with confidence intervals
x = 1:8;
y = [2.1 3.4 4.2 5.8 5.5 6.1 7.3 8.0];
neg = [0.3 0.4 0.2 0.5 0.6 0.3 0.4 0.3];
pos = [0.4 0.3 0.3 0.6 0.5 0.4 0.5 0.4];
errorbar(x, y, neg, pos, 'o-', 'LineWidth', 1.5);
title('Tensile Strength vs. Sample');
xlabel('Sample #');
ylabel('Strength (MPa)');
grid on;Rendered errorbar example
x = 1:8;
y = [2.1 3.4 4.2 5.8 5.5 6.1 7.3 8.0];
neg = [0.3 0.4 0.2 0.5 0.6 0.3 0.4 0.3];
pos = [0.4 0.3 0.3 0.6 0.5 0.4 0.5 0.4];
errorbar(x, y, neg, pos, 'o-', 'LineWidth', 1.5);
title('Tensile Strength vs. Sample');
xlabel('Sample #');
ylabel('Strength (MPa)');
grid on;
Compare this result with other chart types in the plot examples.
Using errorbar with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how errorbar changes the result.
Run a small errorbar example, explain the result, then change one input and compare the output.
FAQ
How do I plot asymmetric error bars?⌄
Pass separate lower and upper error vectors. For vertical-only asymmetric bars, use errorbar(x, y, neg, pos) where neg is the downward extent and pos is the upward extent.
x = 1:5;
y = [2 3 2.5 4 3.5];
neg = [0.1 0.2 0.15 0.3 0.1];
pos = [0.3 0.4 0.2 0.5 0.25];
errorbar(x, y, neg, pos);Can I add horizontal error bars?⌄
Yes. Append "horizontal" to a symmetric or asymmetric form for horizontal-only bars, or use "both" for equal horizontal and vertical lengths. The six-data form errorbar(x, y, yneg, ypos, xneg, xpos) controls all four directions independently.
x = 1:4; y = [3 4 2 5];
errorbar(x, y, 0.2*ones(size(x)), "horizontal");Can I combine error bars with a line or scatter plot?⌄
Yes—errorbar already draws a line through the data points by default. To overlay error bars on a separate plot, call hold on first. The error-bar owner supports its existing style properties, including color and line width; it does not implement every line data property.
plot(x, y, 'b-', 'LineWidth', 2);
hold on;
errorbar(x, y, err, err, 'LineStyle', 'none', 'Color', 'b');Related Plotting functions
2D Charts
area · bar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs · stem
Other
addpoints · ancestor · animatedline · autumn · axes · barh · bone · caxis · cla · clf · clim · colorcube · colororder · cool · copper · copyobj · cylinder · daspect · datacursormode · dataTipTextRow · drawnow · fcontour · figure · fill · fill3 · findobj · fsurf · gobjects · gray · groot · hgload · hgsave · hidden · histogram2 · hold · hot · inferno · isgraphics · ishandle · jet · line · lines · linkaxes · magma · openfig · opengl · pan · parula · patch · pink · plasma · plotmatrix · plotyy · polarhistogram · polarplot · polarscatter · print · quiver3 · ribbon · saveas · savefig · sphere · spring · stackedplot · subtitle · summer · suptitle · text · textscatter · textscatter3 · triplot · turbo · viridis · waitbar · winter · wordcloud · xlabel · xlim · xline · xscale · xtickangle · xtickformat · xticklabels · xticks · ylabel · ylim · yline · yscale · ytickangle · ytickformat · yticklabels · yticks · zlim · zoom
More plotting resources
Source you can read
Every RunMat function's source is public. Read exactly how errorbar is executed, line by line, in Rust.
- View the source for errorbar in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.