contour — Render MATLAB-compatible contour plots (iso-lines).
contour(X, Y, Z, levels) draws iso-lines of the matrix Z projected on the XY plane using MATLAB-compatible defaults. When X and Y are omitted, RunMat assumes 1:m and 1:n axes. The default number of levels matches MATLAB (10).
How contour works in RunMat
Zmust be a real matrix (host tensor or gpuArray). Axis vectors must be monotonically spaced but need not be uniform.- Level inputs may be a scalar (number of levels) or an explicit vector. Vectors must be strictly increasing, matching MATLAB's contract.
- When gpuArray inputs are provided and the shared renderer is active, the iso-lines are generated by a GPU marching-squares kernel without copying data back to the host.
- The CPU fallback mirrors MATLAB semantics and produces identical iso-lines when no GPU is available.
Options
'LevelList', vec/'Levels', vec– provide an explicit, strictly increasing vector of Z values to contour.vecmay be a numeric vector (host tensor or gpuArray). If a scalar is supplied the helper interprets it as the requested number of levels, matching MATLAB.'LevelStep', step– positive finite scalar that determines the spacing between contour levels.'LevelListMode', 'auto' | 'manual'–'auto'resets the helper to evenly spaced defaults;'manual'requires the same call to also pass'LevelList'or'LevelStep'.'LineColor', spec– accepts MATLAB color strings ("r","magenta", etc.), RGB triples, or the literals'auto'/'flat'(use the colormap) and'none'(suppress iso-line overlays when paired withcontourf).
Example
[X, Y] = meshgrid(-2:0.25:2, -2:0.25:2);
z = X .* exp(-X.^2 - Y.^2);
contour(z);
contour(z, [0, 0.5, 1.0]);
contour(z, 'LevelStep', 0.25, 'LineColor', 'none')Related functions to explore
These functions work well alongside contour. Each page has runnable examples you can try in the browser.
bar, contourf, hist, mesh, meshc, plot, scatter, scatter3, stairs, surf, surfc
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how contour works, line by line, in Rust.
- View contour.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.