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, XNeg, XPos, YNeg, YPos)
h = errorbar(ax, ...)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
Y | NumericArray | Yes | — | Data values. |
E | NumericArray | Yes | — | Symmetric Y error magnitudes. |
X | NumericArray | Yes | — | X coordinates. |
Y | NumericArray | Yes | — | Y coordinates. |
YNeg | NumericArray | Yes | — | Negative Y error magnitudes. |
YPos | NumericArray | Yes | — | Positive Y error magnitudes. |
XNeg | NumericArray | Yes | — | Negative X error magnitudes. |
XPos | NumericArray | Yes | — | Positive X error magnitudes. |
ax | NumericScalar | Yes | — | Target axes handle. |
data | Any | Variadic | — | Errorbar positional data arguments. |
props | Any | Variadic | — | Style and name/value properties. |
Returns
| Name | Type | Description |
|---|---|---|
h | NumericScalar | Handle to the created error bar series. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:errorbar:InvalidArgument | Input vectors, error vectors, style arguments, or axes-target forms are malformed. | errorbar: invalid argument |
RunMat:errorbar:Internal | Internal render preparation or GPU vertex generation fails. | errorbar: internal operation failed |
How errorbar works
- Vertical-only and both-direction error-bar forms are supported through the runtime and replay/render stack.
- The returned value is an error-bar handle that can be queried or updated through
getandset. - 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 when plotting-compatible buffers are available for the full input set; otherwise RunMat falls back to host plotting while preserving the same visible result.
Does RunMat run errorbar on the GPU?
Dedicated GPU geometry generation covers supported vertical and both-direction error-bar workflows.
Markers continue to use the shared marker path so line/marker styling stays consistent with the rest of the plotting stack.
GPU memory and residency
errorbar preserves GPU residency when the direct error-bar packer path is available for the full input set. Marker rendering stays aligned with the shared marker path.
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, xn, xp, yn, yp);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;
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. Use the six-argument form errorbar(x, y, yneg, ypos, xneg, xpos) to get both vertical and horizontal bars. If you only want horizontal bars, set the vertical error vectors to zero.
x = 1:4; y = [3 4 2 5];
errorbar(x, y, zeros(size(x)), zeros(size(x)), 0.2*ones(size(x)), 0.3*ones(size(x)));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 handle supports the same set properties as line handles, so you can match colors and widths.
plot(x, y, 'b-', 'LineWidth', 2);
hold on;
errorbar(x, y, err, err, 'LineStyle', 'none', 'Color', 'b');Related Plotting functions
More plotting resources
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. 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 an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 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.