stackedplot — Create a stacked line chart with one y-axis per plotted variable.
stackedplot creates a chart with vertically aligned axes that share one x-axis. Pass a vector for one series, a matrix to place each column on a separate axes, or paired X,Y data to choose the common x coordinates. Table and timetable forms select plottable variables by name, numeric index, logical mask, or supported selector object. Numeric source data remains in its native single, double, logical, or integer storage for chart-property queries; floating values used by the renderer are derived from that source rather than becoming the chart's authoritative data.
Syntax
s = stackedplot(Y)
s = stackedplot(X, Y)
s = stackedplot(tbl)
s = stackedplot(tbl, vars)
s = stackedplot(..., LineSpec)
s = stackedplot(..., Name, Value)
s = stackedplot(parent, ...)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
Y | NumericArray | Yes | — | Vector or matrix data. Matrix columns are plotted in separate stacked axes. |
X | NumericArray | Yes | — | Common x-axis vector. |
Y | NumericArray | Yes | — | Vector or matrix y data. |
tbl | Any | Yes | — | Table or timetable data. |
props | Any | Variadic | — | Variable selectors, line style, and StackedLineChart name-value options. |
Returns
| Name | Type | Description |
|---|---|---|
s | NumericScalar | Handle to the StackedLineChart object. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:stackedplot:InvalidArgument | Input data, table selectors, line style, parent, or StackedLineChart properties are invalid. | stackedplot: invalid argument |
RunMat:stackedplot:Internal | Internal plotting state update fails. | stackedplot: internal operation failed |
How stackedplot works
Ycan be a vector or matrix. Row and column vectors become one stacked axes; matrix columns become separate stacked axes.Xmust be a vector whose length matches the vector length or matrix row count ofY.- Table and timetable inputs select plottable variables by default. Text, cell, struct, and unsupported object variables are skipped unless explicitly selected, in which case the chart errors if no plottable variables remain.
varsandDisplayVariablesuse the shared table variable selector machinery for table inputs, including names, string arrays, cellstr, numeric indices, logical masks, and supported selector objects.DisplayLabelsaccepts text scalars, string arrays, character arrays, or cell arrays of text scalars.- Multiple table or multiple timetable inputs must be the same tabular kind. Matching variable names combine on one stacked axes by default;
CombineMatchingNames=falseseparates them by input. XVariableselects the common x-axis variable from table inputs. It may be one variable shared by all table inputs or one variable per input table. Timetable row times are used automatically, andXVariableis rejected for timetables.- LineSpec and line style name-value properties apply to every child line.
- The returned handle is a
stackedplotchart object.getsupportsType,Parent,DisplayVariables,SourceTable,XVariable,CombineMatchingNames,XData,YData,XLabel,Title,Visible,GridVisible,XLimits,LineWidth,LineStyle, andColor.YDatais a numeric matrix when child lines have matching lengths and a cell array of vectors when multiple source tables have unequal lengths. SourceTablereturns a lightweight provenance snapshot with source table classes and variable names rather than embedding the original table objects in plotting registry state.- All eight integer classes are accepted for numeric X/Y data and for numeric table-variable selectors. Integer selectors are decoded as exact positive indices, so adjacent
uint64values are never collapsed through binary64 conversion. XDataandYDatapreserve native numeric storage and exact integer values. When all Y columns share a class and length,YDatais rebuilt as one same-class matrix; heterogeneous classes or unequal lengths are returned as a cell array of typed vectors.setsupportsTitle,XLabel,DisplayLabels,YLabels,Visible,GridVisible,XLimits,Color,LineStyle,LineWidth,Marker, andMarkerSize.XLimitsaccepts finite or infinite numeric bounds as long as the range is increasing.- Figure handles are accepted as parents. Axes handles, nested grouped
DisplayVariablescells, event-table rendering, interactive chart controls, and native provider-side column splitting are not implemented yet. Automatically resident inputs can use an exact owner-aware host fallback, while explicit GPU input requires RunMat mode.
Examples
Plot each matrix column in a separate stacked axes
Y = [1 10; 2 20; 3 30];
s = stackedplot(Y);Use a common x vector and line style
x = [0 1 2];
Y = [1 10; 2 20; 3 30];
stackedplot(x, Y, '--o', 'LineWidth', 1.5);Plot selected table variables
T = table([1;2;3], [4;5;6], [7;8;9], 'VariableNames', {'Time','A','B'});
s = stackedplot(T, {'A','B'}, 'XVariable', 'Time');
get(s, 'DisplayVariables')Combine matching variables from multiple tables
T1 = table([1;2], 'VariableNames', {'A'});
T2 = table([3;4], 'VariableNames', {'A'});
s = stackedplot(T1, T2, 'A');Using stackedplot with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how stackedplot changes the result.
Run a small stackedplot example, explain the result, then change one input and compare the output.
FAQ
Does stackedplot return line handles?⌄
No. RunMat returns a first-class stackedplot chart handle that owns the child line plots and stacked axes.
Does stackedplot preserve gpuArray residency?⌄
Not currently. Matrix and table inputs must be split into stacked axes and grouped child lines, so RunMat materializes inputs before handing each child line to the renderer. This is tracked for the dedicated GPU/provider audit rather than hidden behind a partial fast path.
Related Plotting functions
2D Charts
area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs · stem
Other
addpoints · ancestor · animatedline · axes · barh · caxis · cla · clf · clim · colorcube · colororder · copyobj · daspect · datacursormode · dataTipTextRow · fcontour · figure · fill · fill3 · findobj · fsurf · gobjects · groot · hgload · hgsave · hidden · histogram2 · hold · line · linkaxes · openfig · opengl · pan · parula · patch · plotmatrix · plotyy · polarhistogram · polarplot · polarscatter · print · quiver3 · ribbon · saveas · savefig · sphere · subtitle · suptitle · text · textscatter · textscatter3 · triplot · waitbar · wordcloud · xlabel · xlim · xline · xscale · xtickangle · xtickformat · xticklabels · xticks · ylabel · ylim · yline · yscale · ytickangle · ytickformat · yticklabels · yticks · zlim · zoom
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how stackedplot is executed, line by line, in Rust.
- View the source for stackedplot 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.