RunMat
GitHub

surf — Create 3-D surface plots from height grids or mesh coordinates with MATLAB-compatible surf syntax.

surf creates shaded 3-D surfaces from vector axes plus height data or from explicit mesh coordinate matrices. It returns a surface handle and follows MATLAB-compatible argument and property behavior.

Syntax

h = surf(Z)
h = surf(X, Y, Z)
h = surf(Z, Name, Value, ...)
h = surf(X, Y, Z, Name, Value, ...)

Inputs

NameTypeRequiredDefaultDescription
ZNumericArrayYesSurface height grid.
XNumericArrayYesX axis vector/meshgrid matrix matching Z columns.
YNumericArrayYesY axis vector/meshgrid matrix matching Z rows.
propsAnyVariadicName/value surface style options.

Returns

NameTypeDescription
hNumericScalarHandle to the rendered surface plot.

Errors

IdentifierWhenMessage
RunMat:surf:InvalidArgumentSurface/grid/axis inputs or style name/value arguments are invalid.surf: invalid argument
RunMat:surf:InternalInternal surface construction or render preparation fails unexpectedly.surf: internal operation failed

How surf works

  • surf(Z) uses implicit axes, while surf(X, Y, Z) accepts either vector axes or meshgrid-style coordinate matrices, following MATLAB surf call forms.
  • The returned value is a surface handle that can be inspected and updated through get and set.
  • Surface plots naturally interact with view, zlabel, colorbar, colormap, and shading because they all operate on the same subplot-local axes state.
  • GPU-backed surface rendering is the preferred path when exported buffers and the shared plotting device are available; otherwise RunMat gathers once and renders the same surface semantics on the host path.
  • surf is the shaded/fill-oriented member of the surface family, while mesh emphasizes wireframe rendering and surfc adds contour overlays.

Does RunMat run surf on the GPU?

The surface pipeline is shared across multiple plot families, which keeps surf aligned with image, contour-composite, and surface-style rendering behavior.

Surface color limits and subplot-local metadata stay consistent regardless of whether the geometry is emitted from GPU buffers or host tensors.

GPU memory and residency

surf preserves GPU residency on the happy path through the shared surface rendering pipeline. When a direct GPU render path is not available for the active input combination, RunMat gathers once and builds the same surface plot semantics on the fallback path.

Examples

Create a shaded surface from a height grid

[X, Y] = meshgrid(linspace(-2, 2, 80), linspace(-2, 2, 80));
Z = sin(X.^2 + Y.^2) ./ (1 + X.^2 + Y.^2);
surf(X, Y, Z);

Pair surf with colormap, shading, and colorbar

[X, Y] = meshgrid(linspace(-3, 3, 100), linspace(-3, 3, 100));
Z = cos(X) .* sin(Y);
surf(X, Y, Z);
colormap('jet');
shading interp;
colorbar;

Adjust camera state and z-axis labeling for a surface

[X, Y] = meshgrid(linspace(-2, 2, 60), linspace(-2, 2, 60));
Z = X .* exp(-X.^2 - Y.^2);
h = surf(X, Y, Z);
zlabel('Height');
view(45, 30);
get(h, 'Type')

Expected output:

ans =
    'surface'

Damped radial ripple with interpolated shading

[X, Y] = meshgrid(linspace(-4, 4, 200), linspace(-4, 4, 200));
R = sqrt(X.^2 + Y.^2) + 0.01;
Z = sin(3*R) ./ R;

surf(X, Y, Z);
shading interp;
colormap('turbo');
colorbar;
title('Damped Radial Wavefield');
xlabel('x');
ylabel('y');
zlabel('Amplitude');
view(35, 25);
Expected output:
Damped radial ripple with interpolated shading

Using surf with coding agents

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

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

FAQ

How do I change the colormap on a surf plot?

Call colormap after surf to swap the palette. The colormap applies to the current axes, so it works per-subplot.

surf(X, Y, Z);
colormap('turbo');

Any named colormap ('parula', 'jet', 'hot', etc.) or an Nx3 matrix of RGB values works here.

How do I rotate or set the 3-D viewing angle?

Use view(az, el) where az is the azimuth in degrees and el is the elevation. For example, view(45, 30) gives you a 45-degree orbit at 30 degrees above the xy-plane. view(3) is a shortcut for the default 3-D perspective, and view(2) snaps to a top-down 2-D projection.

What's the difference between surf and mesh?

surf renders a shaded, filled surface where face colors come from the colormap. mesh draws only the wireframe grid lines with no face fill. Use surf when you want to visualize the shape as a solid surface, and mesh when you want to see through the geometry to understand the grid structure underneath.

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 · 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 · print · suptitle · xline · yline

More plotting resources

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how surf 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.