RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

LicensePrivacy
/
See all docs
Builtin Reference
    • addpoints
    • ancestor
    • animatedline
    • area
    • axes
    • axis
    • bar
    • barh
    • box
    • caxis
    • cla
    • clf
    • clim
    • colorbar
    • colorcube
    • colormap
    • colororder
    • contour
    • contour3
    • contourf
    • copyobj
    • daspect
    • datacursormode
    • dataTipTextRow
    • errorbar
    • fcontour
    • figure
    • fill
    • fill3
    • findobj
    • fsurf
    • gca
    • gcf
    • get
    • gobjects
    • grid
    • groot
    • heatmap
    • hgload
    • hgsave
    • hidden
    • hist
    • histogram
    • histogram2
    • hold
    • image
    • imagesc
    • imshow
    • legend
    • line
    • linkaxes
    • loglog
    • mesh
    • meshc
    • openfig
    • opengl
    • pan
    • parula
    • patch
    • pie
    • plot
    • plot3
    • plotmatrix
    • plotyy
    • polarhistogram
    • polarplot
    • polarscatter
    • print
    • quiver
    • quiver3
    • ribbon
    • saveas
    • savefig
    • scatter
    • scatter3
    • semilogx
    • semilogy
    • set
    • sgtitle
    • shading
    • sphere
    • stackedplot
    • stairs
    • stem
    • subplot
    • subtitle
    • suptitle
    • surf
    • surfc
    • text
    • textscatter
    • textscatter3
    • title
    • triplot
    • view
    • waitbar
    • wordcloud
    • xlabel
    • xlim
    • xline
    • xscale
    • xtickangle
    • xtickformat
    • xticklabels
    • xticks
    • ylabel
    • ylim
    • yline
    • yscale
    • ytickangle
    • ytickformat
    • yticklabels
    • yticks
    • zlabel
    • zlim
    • zoom

subplot — Select subplot grid locations to create multi-panel axes layouts with MATLAB-compatible subplot behavior.

subplot(m, n, p) selects or creates an axes position inside an m-by-n figure grid and returns its handle. It follows MATLAB-compatible subplot indexing and current-axes selection behavior.

Syntax

ax = subplot(rows, cols, position)

Inputs

NameTypeRequiredDefaultDescription
rowsSizeArgYes—Number of subplot rows.
colsSizeArgYes—Number of subplot columns.
positionSizeArgYes—1-based subplot position in row-major order.

Returns

NameTypeDescription
axNumericScalarEncoded handle for the selected subplot axes.

Errors

IdentifierWhenMessage
RunMat:subplot:InvalidArgumentRows/cols/position are unsupported, non-scalar, non-finite, or non-positive.subplot: invalid argument
RunMat:subplot:IndexOutOfRangePosition is outside the configured subplot grid.subplot: subplot index is out of range for the grid
RunMat:subplot:InternalInternal subplot state operation fails.subplot: internal operation failed

How subplot works

  • The returned value is an axes handle that can be passed explicitly to later plotting commands.
  • Subplot-local metadata stays isolated per axes: titles, legends, limits, log modes, and 3-D view state are all tracked independently.
  • Subsequent plotting commands operate on the selected subplot unless another axes handle is passed explicitly.
  • Indices are one-based in the MATLAB style. subplot(2, 2, 3) selects the third slot in row-major order.
  • The documented grid controls use single or double values. RunMat can additionally parse typed-integer scalar controls exactly when RunMat extensions are enabled; strict compatibility mode rejects that extra form before changing figure state.

Examples

Create a 2x2 subplot layout

subplot(2, 2, 1);
plot(0:0.1:1, (0:0.1:1).^2);
subplot(2, 2, 2);
scatter(1:5, [5 4 3 2 1]);

Capture and reuse an axes handle explicitly

ax = subplot(1, 2, 2);
plot(ax, 0:0.1:1, sin(0:0.1:1));
get(ax, 'Type')

Expected output:

ans =
    'axes'

Show that subplot-local state stays isolated

subplot(1, 2, 1);
semilogx(logspace(0, 2, 50), logspace(0, 2, 50));
subplot(1, 2, 2);
plot(1:5, 1:5);

Expected output:

% Only the first subplot uses a logarithmic x-axis

Using subplot with coding agents

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

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

FAQ

How do I control the number of rows and columns in a subplot layout?⌄

The first two arguments to subplot(m, n, p) set the grid dimensions: m rows and n columns. The third argument p selects which slot to activate, counted in row-major order starting at 1. subplot(3, 1, 2) gives you the middle row of a three-row single-column layout.

Can two subplots share the same x-axis range?⌄

Set matching limits on both axes manually with axis or set. There's no automatic linkaxes yet, but explicit limits keep them in sync.

subplot(2, 1, 1); plot(0:10, rand(1, 11)); axis([0 10 0 1]);
subplot(2, 1, 2); plot(0:10, rand(1, 11)); axis([0 10 0 1]);
Can I make subplots of unequal sizes?⌄

You can span multiple grid slots by passing a vector as the third argument. subplot(2, 2, [1 2]) creates a subplot that spans the entire top row of a 2x2 grid, while the bottom row keeps two separate panels.

Can the grid controls be typed integers?⌄

The compatibility surface documents single and double controls. If RunMat extensions are enabled, all eight native integer scalar classes are also accepted and parsed exactly; strict compatibility mode rejects that extra form.

Related Plotting functions

2D Charts

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

3D & Surface

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

Images

image · imagesc · imshow

Axes & Layout

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

Appearance

colorbar · colormap · legend · shading

Handle Access

gca · gcf · get · set

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 · stackedplot · 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

More plotting resources

  • Choosing the right plot type
  • Styling plots and axes
  • Plot replay and export
  • Complete plotting guide

Open-source implementation

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

  • View the source for subplot 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.

Getting started · Benchmarks · Pricing

Download RunMat

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

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How subplot works
  • Examples
  • Create a 2x2 subplot layout
  • Capture and reuse an axes handle explicitly
  • Show that subplot-local state stays isolated
  • Using subplot with coding agents
  • FAQ
  • Related Plotting functions
  • 2D Charts
  • 3D & Surface
  • Images
  • Axes & Layout
  • Appearance
  • Handle Access
  • Other
  • More plotting resources
  • Open-source implementation
  • About RunMat