figure — Create or select plotting figures in MATLAB and RunMat.

figure creates a new plotting figure or selects an existing one as current. With no arguments (or 'next') it allocates a fresh handle; passing a positive numeric handle selects that figure, creating it if needed. figure also accepts figure property/value pairs such as 'Name', 'NumberTitle', 'Visible', and 'Color'. Handle selection, creation, and property assignment behavior follow MATLAB semantics.

Syntax

fig = figure()
fig = figure(h)
fig = figure(property, value, ...)
fig = figure(h, property, value, ...)

Inputs

NameTypeRequiredDefaultDescription
hNumericScalarNo"next"Figure handle or 'next' to create/select the next figure.
propertiesPropertyNameVariadicFigure property/value pairs such as 'Name', 'NumberTitle', 'Visible', or 'Color'.
propertiesPropertyNameVariadicFigure property/value pairs to apply after selecting or creating the figure.

Returns

NameTypeDescription
figNumericScalarFigure handle.

Errors

IdentifierWhenMessage
RunMat:figure:InvalidArgumentProvided figure handle argument is invalid.figure: invalid argument

How figure works

  • figure() creates a new figure and returns its numeric handle.
  • figure(n) selects figure n. If that handle does not exist yet, RunMat creates it.
  • figure('next') creates a new figure instead of selecting an existing one.
  • figure('Property', value, ...) creates a fresh figure and applies the requested figure properties.
  • figure(n, 'Property', value, ...) selects or creates figure n and applies the requested figure properties.
  • The selected figure becomes the target for subsequent plotting commands such as plot, subplot, gca, clf, and hold.

Options

  • 'Name' sets the figure window name and can be inspected later with get(f, 'Name').
  • 'NumberTitle' accepts logical values or MATLAB-style 'on'/'off' strings.
  • 'Visible' accepts logical values or MATLAB-style 'on'/'off' strings. Hidden figures keep their graphics state but do not open or update interactive windows until made visible again.
  • 'Color' and 'BackgroundColor' accept exact MATLAB color letters, full color names such as 'black', or RGB triples, and update the figure background color.

Does RunMat run figure on the GPU?

figure performs no provider dispatch. GPU-resident arrays passed to later plotting calls may still remain on device when the renderer supports that path.

GPU memory and residency

figure only updates plotting state and returns a host-side numeric handle. It does not affect array residency.

Examples

Create a fresh figure

f = figure()

Expected output:

% f is a positive numeric figure handle

Create another figure with the explicit 'next' selector

f1 = figure();
f2 = figure("next")

Expected output:

% f2 is a different figure handle from f1

Select a specific figure handle

figure(3);
plot(1:5, [1 4 2 5 3]);

Expected output:

% plotting now targets figure 3

Create a named figure with MATLAB-style property pairs

f = figure('Name', 'demo', 'NumberTitle', 'off', 'Visible', 'off');
plot(1:5, [1 4 2 5 3]);

Expected output:

% f is a figure handle whose Name, NumberTitle, and Visible properties are set

Using figure with coding agents

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

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

FAQ

Does figure(n) require the handle to exist already?

No. RunMat selects figure n, creating it on demand if necessary.

What does figure('next') do?

It forces creation of a new figure rather than reusing an existing handle.

Can figure set window properties at creation time?

Yes. Pass alternating property/value pairs, either directly or after a numeric handle: figure('Name', 'demo') or figure(3, 'Name', 'demo', 'NumberTitle', 'off').

Does figure draw anything by itself?

No. It only manages the active figure selection. Plotting happens when you call builtins like plot, scatter, or surf.

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 · subplot · title · view · zlabel

Appearance

colorbar · colormap · legend · shading

Handle Access

gca · gcf · get · set

Other

cla · clf · 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 figure 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.