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 does the contour function behave in MATLAB / 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 of using contour in MATLAB / RunMat
contour(peaks(50));
contour(x, y, z, 20);
contour(x, y, z, [0, 0.5, 1.0]);
contour(x, y, z, 'LevelStep', 0.25, 'LineColor', 'none')Source & Feedback
- Source code: `crates/runmat-runtime/src/builtins/plotting/ops/contour.rs`
- Found a bug? Open an issue with a minimal reproduction.