RunMat
GitHub

contour — Create contour line plots for level sets, iso-lines, and MATLAB contour workflows.

contour creates contour line plots from scalar fields. In RunMat it returns a contour handle, supports MATLAB-style level-list and level-step workflows, and uses the shared contour-generation pipeline. It is the line-oriented member of the contour family, while contourf is the filled-region counterpart.

How contour works

  • contour(Z) uses implicit axes, while contour(X, Y, Z) accepts explicit vector or matrix coordinates.
  • The builtin returns a contour handle that works with the plotting property system.
  • Levels can be controlled through explicit level lists, level counts, or level-step workflows.
  • Contour state is subplot-local and composes naturally with colormap, colorbar, and surface/composite builtins.
  • GPU-aware contour generation is used when the shared plotting path can operate directly on GPU-resident scalar fields.

Options

  • 'LevelList' / 'Levels' accepts an explicit, strictly increasing vector of contour values.
  • 'LevelStep' specifies evenly spaced contour levels.
  • 'LineColor' accepts MATLAB color strings, RGB triples, and contour-specific modes such as 'auto' or 'none' where supported.

Examples

Create a contour line plot from a scalar field

[X, Y] = meshgrid(-2:0.25:2, -2:0.25:2);
Z = X .* exp(-X.^2 - Y.^2);
contour(X, Y, Z);

Use explicit contour levels

[X, Y] = meshgrid(-2:0.25:2, -2:0.25:2);
Z = X .* exp(-X.^2 - Y.^2);
contour(X, Y, Z, [0 0.25 0.5]);

Inspect the returned contour handle

[X, Y] = meshgrid(1:20, 1:20);
Z = X + Y;
h = contour(X, Y, Z);
get(h, 'Type')

Expected output:

ans =
    'contour'

Temperature-style level sets

[X, Y] = meshgrid(linspace(-3, 3, 120), linspace(-3, 3, 120));
Z = 2*exp(-((X-1).^2 + Y.^2)) + 1.5*exp(-((X+1.5).^2 + (Y-1).^2)) - exp(-(X.^2 + (Y+1.5).^2));

contour(X, Y, Z, 20);
colormap('turbo');
colorbar;
title('Thermal Field — Level Sets');
xlabel('x (m)');
ylabel('y (m)');
axis equal;
Expected output:
Temperature-style level sets

FAQ

How do I set specific contour levels?

Pass a vector of values as the fourth argument. Each value becomes one contour line.

contour(X, Y, Z, [0.1 0.3 0.5 0.7 0.9]);

If you pass a scalar instead, it's interpreted as the number of levels (e.g., contour(X, Y, Z, 20) draws 20 automatically spaced levels).

Can I add labels to the contour lines?

Use clabel after contour to annotate the lines with their level values. Pass the contour handle to clabel so it knows which plot to label.

[C, h] = contour(X, Y, Z);
clabel(C, h);
What's the difference between contour and contourf?

contour draws line-only iso-curves — the regions between lines are transparent. contourf fills those regions with colors from the active colormap. Use contour when you want to overlay on other plots or keep the background visible, and contourf when the filled color bands are the primary visualization.

2D Charts

area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs · stem

3D & Surface

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 · figure · fill3 · hold · patch · suptitle · xline · yline

More plotting resources

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how contour works, line by line, in Rust.

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.

Getting started · Benchmarks · Pricing

Try RunMat for free

Write code or describe what you want to compute. The sandbox is free, no account required.