RunMat
GitHub

stem — Create stem plots for discrete sequences with MATLAB-compatible stem syntax and styling controls.

stem creates vertical stems from a baseline to sample values and returns a graphics handle. It supports MATLAB-compatible shorthand, explicit x/y forms, and shared plot-property styling workflows.

Syntax

h = stem(Y)
h = stem(Y, LineSpec)
h = stem(Y, Name, Value, ...)
h = stem(X, Y)
h = stem(X, Y, LineSpec)
h = stem(X, Y, Name, Value, ...)
All supported stem forms
h = stem(Y)
h = stem(Y, LineSpec)
h = stem(Y, Name, Value, ...)
h = stem(X, Y)
h = stem(X, Y, LineSpec)
h = stem(X, Y, Name, Value, ...)
h = stem(ax, Y)
h = stem(ax, Y, LineSpec)
h = stem(ax, Y, Name, Value, ...)
h = stem(ax, X, Y)
h = stem(ax, X, Y, LineSpec)
h = stem(ax, X, Y, Name, Value, ...)

Inputs

NameTypeRequiredDefaultDescription
YNumericArrayYesY samples. X defaults to 1:numel(Y).
lineSpecStyleSpecYesLine style shorthand such as '--r'.
propsAnyVariadicName/value style properties.
XNumericArrayYesX samples.
YNumericArrayYesY samples.
axAxesHandleYesTarget axes handle.

Returns

NameTypeDescription
hNumericScalarHandle to the rendered stem plot.

Errors

IdentifierWhenMessage
RunMat:stem:InvalidArgumentInput data, axes targeting, or style arguments are invalid.stem: invalid argument
RunMat:stem:InternalInternal plot construction or rendering fails unexpectedly.stem: internal operation failed

How stem works

  • stem(y) uses implicit x-values 1:n, while stem(x, y) uses explicit paired coordinates.
  • The returned value is a stem plot handle that works with get and set.
  • Baseline visibility, markers, fill behavior, display names, and line styling all flow through the shared plotting property model.
  • The plot remains subplot-local and composes naturally with legends and axes-local state.
  • GPU-backed geometry is used when plotting-compatible buffers are available, with marker rendering sharing the point/marker pipeline.

Does RunMat run stem on the GPU?

Stem line geometry can be emitted directly from GPU buffers on the happy path.

Markers use the shared rendering path, which keeps style semantics aligned with the rest of the plotting stack.

GPU memory and residency

stem preserves GPU residency when the direct stem packer path is available. Marker rendering stays on the shared marker path.

Examples

Create a stem plot from y-values only

stem([1 4 2 5 3]);

Use explicit x-values and filled markers

x = 0:5;
h = stem(x, [0 1 0 2 0 3]);
set(h, 'Filled', true, 'DisplayName', 'samples');
legend;

Inspect a stem handle after plotting

h = stem(1:5, [2 1 3 2 4]);
get(h, 'Type')

Expected output:

ans =
    'stem'

Discrete sampled signal

n = 0:31;
x = sin(2*pi*n/16) .* (0.9 .^ n);

stem(n, x);
title('Sampled Decaying Sinusoid');
xlabel('Sample index n');
ylabel('x[n]');
grid on;
Expected output:
Discrete sampled signal

Using stem with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how stem changes the result.

Run a small stem example, explain the result, then change one input and compare the output.

FAQ

When should I use stem instead of plot?

stem is designed for discrete sequences where each sample is an independent value at a specific index—think impulse responses, sampled signals, or coefficient arrays. plot connects points with a continuous line, which implies interpolation between samples. If your data is inherently discrete and the gaps between samples matter, stem communicates that visually.

How do I customize the markers on a stem plot?

Use the handle returned by stem with set to change marker shape, size, fill, and color.

h = stem(1:8, [3 1 4 1 5 9 2 6]);
set(h, 'Marker', 's', 'MarkerSize', 8, 'Filled', true, 'MarkerFaceColor', 'r');

Marker properties go through the same shared property model as plot and scatter, so the same property names work.

Can I change the baseline of a stem plot?

Yes. Set the 'BaseValue' property on the stem handle to shift the baseline from the default of 0.

h = stem(1:5, [2 4 1 3 5]);
set(h, 'BaseValue', 2);

Stems will then extend from y=2 to each data point rather than from y=0.

2D Charts

area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs

3D & Surface

contour · contour3 · contourf · mesh · meshc · plot3 · quiver · scatter3 · surf · surfc

Images

image · imagesc · imshow

Axes & Layout

axis · box · grid · sgtitle · subplot · title · view · zlabel

Appearance

colorbar · colormap · legend · shading

Handle Access

gca · gcf · get · set

Other

cla · clf · figure · fill3 · hold · patch · polarplot · print · suptitle · xline · yline

More plotting resources

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how stem is executed, line by line, in Rust.

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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.