stairs — Create staircase line plots for sampled or piecewise-constant data with MATLAB-compatible stairs syntax.
stairs creates a piecewise-constant line from Y alone or paired X,Y coordinates and returns a graphics handle. X and Y may use single, double, or any of the eight integer classes. RunMat keeps the native source class and exact values for XData, YData, and saved figure scenes; the plotting renderer receives a derived floating representation, so rendering does not replace or round the authoritative source data.
Syntax
h = stairs(Y)
h = stairs(X, Y)
h = stairs(X, Y, LineSpec)
h = stairs(X, Y, Name, Value, ...)
h = stairs(ax, Y)
h = stairs(ax, X, Y)
h = stairs(ax, X, Y, LineSpec)
h = stairs(ax, X, Y, Name, Value, ...)Inputs
Y- Type
NumericArray- Required
- Yes
- Description
- Y samples. X defaults to 1:numel(Y).
X- Type
NumericArray- Required
- Yes
- Description
- X samples.
Y- Type
NumericArray- Required
- Yes
- Description
- Y samples.
lineSpec- Type
StyleSpec- Required
- Yes
- Description
- Line style shorthand such as '--r'.
props- Type
Any- Required
- Variadic
- Description
- Name/value style properties.
ax- Type
AxesHandle- Required
- Yes
- Description
- Target axes handle.
Returns
h- Type
NumericScalar- Description
- Handle to the rendered stairs plot.
Errors
RunMat:stairs:InvalidArgument- When
- Input data, axes targeting, or style arguments are invalid.
- Message
stairs: invalid argument
RunMat:stairs:Internal- When
- Internal plot construction or rendering fails unexpectedly.
- Message
stairs: 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
stairs(y) uses implicit x-values 1:n, while stairs(x, y) uses explicit paired coordinates.
The returned value is a plot handle that works with get and set.
Marker styling and display names can be updated through the same handle/property system used by line plots.
XData and YData retain the input numeric class, shape, and exact host values, including int64 and uint64 values above flintmax.
Figure-scene serialization preserves typed source data. Loading an older scene without typed source fields reconstructs ordinary double source data for backward compatibility.
Step-plot rendering is subplot-local and respects current axes state just like plot and scatter.
GPU-backed geometry is preferred when exported buffers and the shared plotting device are available.
Rendering and residency
stairs can use direct GPU-backed geometry for supported floating buffers. Integer source buffers use an exact owner-aware gather when direct export is unavailable; automatic residency remains transparent and the renderer never interprets integer bytes as floating values.
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
Coordinates use real single/double Tensor storage or native integer storage. Scalar logical coordinates pass through the existing NumericInput double conversion; logical arrays, complex arrays, sparse arrays, categorical and datetime coordinate objects do not have a NumericInput representation and are not implemented by this chart owner.
stairs(Y), stairs(X,Y), leading axes, and explicit-pair LineSpec/name-value styles use the existing stairs parser. A y-only scalar is normalized through the same NumericInput owner as explicit pairs. Y-only style suffixes are not currently parsed as that form: use explicit X/Y when styling construction. X and Y are paired by element count and remain native source properties. Empty coordinates are rejected by StairsPlot; the inherited minimum-one implicit index rule is not a promise of empty-input support. Step geometry and markers are derived display caches, not source-data replacements.
Examples
Plot a sampled staircase signal
t = 0:5;
stairs(t, cumsum([1 -1 2 -2 1 0]));Use MATLAB-style y-only shorthand
stairs([3 1 4 1 5 9]);Style a stairs object and label it for the legend
h = stairs(0:4, [1 2 2 3 5]);
set(h, 'Color', 'm', 'LineWidth', 2, 'DisplayName', 'sampled signal');
legend;Piecewise-constant step response
t = 0:0.5:10;
y = 1 - exp(-0.5*t);
h = stairs(t, y);
set(h, 'LineWidth', 2);
title('First-Order Step Response');
xlabel('Time (s)');
ylabel('Output');
grid on;Rendered stairs example
t = 0:0.5:10;
y = 1 - exp(-0.5*t);
h = stairs(t, y);
set(h, 'LineWidth', 2);
title('First-Order Step Response');
xlabel('Time (s)');
ylabel('Output');
grid on;
Compare this result with other chart types in the plot examples.
Using stairs with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how stairs changes the result.
Run a small stairs example, explain the result, then change one input and compare the output.
FAQ
When should I use stairs instead of plot?⌄
stairs draws piecewise-constant steps between points, while plot linearly interpolates. Use stairs when your data is held constant between samples—DAC output, quantized signals, sample-and-hold systems, or any situation where the value doesn't change smoothly between observations.
How do I visualize a digital signal with stairs?⌄
Pass your time vector and signal values directly. The staircase rendering naturally represents digital/discrete-time signals where values snap between levels.
t = 0:0.01:1;
signal = double(square(2*pi*5*t) > 0);
stairs(t, signal);
ylim([-0.2 1.2]);This avoids the misleading diagonal transitions that plot would draw between high and low states.
Can I add markers to a stairs plot?⌄
Yes. Set the 'Marker' property on the returned handle, just like you would with plot.
h = stairs(0:4, [1 3 2 4 1]);
set(h, 'Marker', 'o', 'MarkerSize', 6);Markers appear at each data point (the step corners), not along the flat segments.
Related Plotting functions
2D Charts
area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · 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 stairs is executed, line by line, in Rust.
- View the source for stairs 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.