stackedplot — Create a stacked line chart with one y-axis per plotted variable.
stackedplot(Y) plots vector or matrix data with matrix columns in separate stacked axes and row/column vectors as one series. stackedplot(X,Y) uses a common x vector. stackedplot(tbl), stackedplot(tbl,vars), stackedplot(tbl1,...,tblN), and stackedplot({tbl1,...,tblN}) plot selected numeric, logical, datetime, duration, or categorical table/timetable variables and use timetable row times as x data when available.
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.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 provider-resident column splitting are not implemented yet and raise explicit errors or documented compatibility fallbacks.
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 · cla · clf · colorcube · colororder · copyobj · daspect · datacursormode · dataTipTextRow · fcontour · figure · 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 · textscatter · textscatter3 · triplot · waitbar · wordcloud · xline · xscale · xtickangle · xtickformat · xticklabels · xticks · yline · yscale · ytickangle · ytickformat · yticklabels · yticks · 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.