area — Create filled area plots in MATLAB and RunMat.
area creates filled area plots from vector or matrix-style inputs. It returns an area handle, supports baseline/stacked behaviors, and participates in the shared MATLAB/RunMat plotting handle-property system.
Syntax
h = area(Y)
h = area(Y, LineSpec)
h = area(Y, Name, Value, ...)
h = area(X, Y)
h = area(X, Y, LineSpec)
h = area(X, Y, Name, Value, ...)All supported area forms
h = area(Y)
h = area(Y, LineSpec)
h = area(Y, Name, Value, ...)
h = area(X, Y)
h = area(X, Y, LineSpec)
h = area(X, Y, Name, Value, ...)
h = area(ax, Y)
h = area(ax, Y, Name, Value, ...)
h = area(ax, X, Y)
h = area(ax, X, Y, Name, Value, ...)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
Y | NumericArray | Yes | — | Y data vector or matrix. Columns are rendered as stacked series. |
lineSpec | StyleSpec | Yes | — | Line/color shorthand such as '--r'. |
props | Any | Variadic | — | Name/value style properties such as Color, LineWidth, and BaseValue. |
X | NumericArray | Yes | — | X coordinates matching the row count of Y. |
ax | AxesHandle | Yes | — | Target axes handle. |
Returns
| Name | Type | Description |
|---|---|---|
h | NumericScalar | Handle to the first area series in the rendered chart. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:area:InvalidArgument | Input data, style tokens, or name/value options are invalid. | area: invalid argument |
RunMat:area:Internal | Renderer/GPU conversion fails during chart construction. | area: internal operation failed |
How area works
area(y)uses implicit x-values1:n, whilearea(x, y)uses explicit x coordinates.- Matrix-style
yinputs create stacked area series in the MATLAB style. - The returned value is an area-handle object that works with
getandset. - Baseline and color workflows flow through the shared plotting property model.
- Stacked-series geometry can be emitted directly from GPU buffers on the happy path.
Options
'BaseValue'sets the baseline used by area filling.- Color and display-name workflows are available through the returned handle and the shared plotting property path.
Does RunMat run area on the GPU?
The direct area path emits filled geometry from GPU data on the happy path.
Baseline semantics, stacked-series behavior, and handle/property workflows remain aligned across GPU and fallback paths.
GPU memory and residency
area preserves GPU residency on the direct path, including stacked-series geometry generation. Fallback rendering still preserves the same visible semantics and handle behavior when a direct GPU path is not available.
Examples
Create a basic filled area plot
x = 0:0.1:1;
area(x, x.^2);Create stacked area series from a matrix
x = 1:5;
Y = [1 2 1; 2 1 2; 3 2 1; 2 3 2; 1 2 3];
area(x, Y);Change the baseline and label the series through the handle
x = 0:0.2:2;
h = area(x, sin(x) + 2);
set(h, 'BaseValue', 1, 'DisplayName', 'offset area');
legend;Stacked energy mix
years = 2018:2025;
solar = [5 8 12 18 25 33 42 50];
wind = [10 14 18 22 28 32 36 40];
hydro = [30 30 29 28 27 27 26 26];
mix = [solar; wind; hydro]';
area(years, mix);
title('Energy Generation Mix');
xlabel('Year');
ylabel('TWh');
legend('Solar', 'Wind', 'Hydro');
grid on;
Using area with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how area changes the result.
Run a small area example, explain the result, then change one input and compare the output.
FAQ
How do I create a stacked area chart?⌄
Pass a matrix as the y-data. Each column becomes a stacked series, and RunMat accumulates them vertically so the total is visible at the top.
x = 1:6;
Y = [2 3 1; 1 2 2; 3 1 2; 2 2 3; 1 3 1; 2 1 3];
area(x, Y);
legend('A', 'B', 'C');How do I control the transparency of an area plot?⌄
Set 'FaceAlpha' on the area handle to a value between 0 (fully transparent) and 1 (fully opaque). This is useful when overlaying multiple area series without stacking.
area(x, y1);
hold on;
h = area(x, y2);
set(h, 'FaceAlpha', 0.4);What's the difference between area and plot?⌄
area fills the region between the data line and the baseline, giving a visual sense of cumulative magnitude. plot just draws the line. Use area when the filled region conveys meaning—cumulative totals, part-to-whole breakdowns, or emphasizing the magnitude of a signal relative to a baseline.
Related Plotting functions
More plotting resources
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how area is executed, line by line, in Rust.
- View the source for area 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.