surfc — Create composite surface-and-contour plots for scalar fields with MATLAB surfc semantics and projected contour overlays.
surfc is the composite member of the surface family: it combines a shaded surf-style surface with contour lines projected onto the base plane. In RunMat the returned handle is the primary surface handle, while the contour overlay is added as the secondary composite child. That keeps the composite behavior explicit without reintroducing a separate legacy plotting stack.
How surfc works
surfcshares the same surface semantics assurffor the primary surface object.- The returned handle is the surface handle for the composite result, while contour overlays are attached as the secondary composite plot content.
- The contour overlay uses the same modern contour-generation path as
contour, rather than a one-off composite implementation. - Colormap, colorbar, view, and subplot-local state all operate on the composite through the same shared axes metadata model.
- GPU-aware execution applies to both the surface side and the contour side where supported.
Examples
Create a shaded surface with projected contour lines
[X, Y] = meshgrid(linspace(-2, 2, 60), linspace(-2, 2, 60));
Z = X .* exp(-X.^2 - Y.^2);
surfc(X, Y, Z);Style the composite with colormap and camera controls
[X, Y] = meshgrid(linspace(-3, 3, 80), linspace(-3, 3, 80));
Z = cos(X) .* sin(Y);
h = surfc(X, Y, Z);
colormap('turbo');
colorbar;
view(45, 25);Inspect the returned primary surface handle
[X, Y] = meshgrid(1:20, 1:20);
Z = X + Y;
h = surfc(X, Y, Z);
get(h, 'Type')Expected output:
ans =
'surface'FAQ
Where do the contour lines appear in a surfc plot?⌄
The contour lines are projected onto the base plane (the z-minimum of the axes). They sit below the surface as a 2-D footprint of the height field. The contour overlay uses the same colormap as the surface, so the colors stay consistent.
When should I use surfc vs calling surf and contour separately?⌄
surfc handles the composite in one call — the contour is automatically projected to the base plane and shares the surface's colormap and axes state. If you call surf and contour separately, the contour sits at z=0 by default and you'd need to manage hold state and z-placement yourself. Use surfc unless you need the contour at a custom z-level or with different level spacing than the default.
Can I control how many contour levels surfc draws?⌄
The contour overlay in surfc uses the default level-generation logic from the contour pipeline. If you need explicit control over level count or spacing, call surf and contour separately so you can pass a level vector to contour directly.
Related Plotting functions
More plotting resources
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how surfc works, line by line, in Rust.
- View surfc.rs on GitHub
- Learn how the 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 — faster, on any GPU, with no license required.
- Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
- Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
- A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.