RunMat
GitHub

contourf — Create filled contour plots in MATLAB and RunMat.

contourf creates filled contour plots by coloring regions between contour levels. It returns a contour-fill handle and shares contour-level generation semantics with contour in MATLAB and RunMat.

Syntax

h = contourf(Z)
h = contourf(Z, V)
h = contourf(Z, Name, Value, ...)
h = contourf(Z, V, Name, Value, ...)
h = contourf(X, Y, Z)
h = contourf(X, Y, Z, V)
h = contourf(X, Y, Z, V, Name, Value, ...)

Inputs

NameTypeRequiredDefaultDescription
ZNumericArrayYesContour height grid.
VAnyYesContour level count/value vector.
propsAnyVariadicName/value contour options.
XNumericArrayYesX axis vector/meshgrid matrix matching Z rows.
YNumericArrayYesY axis vector/meshgrid matrix matching Z columns.

Returns

NameTypeDescription
hNumericScalarHandle to filled contour plot.

Errors

IdentifierWhenMessage
RunMat:contourf:InvalidArgumentContour input arrays, level arguments, or name/value options are invalid.contourf: invalid argument
RunMat:contourf:InternalInternal filled-contour render preparation fails unexpectedly.contourf: internal operation failed

How contourf works

  • contourf(Z) uses implicit axes, while contourf(X, Y, Z) accepts explicit coordinates.
  • The returned value is a contour-fill handle in the plotting object system.
  • Level-list, level-count, and related contour workflows mirror the broader contour family semantics.
  • contourf works naturally with colorbar and colormap because filled regions are fundamentally color-mapped scalar ranges.
  • Filled contours and optional line overlays are handled through the shared contour stack.

Examples

Create a filled contour plot

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

Use explicit levels with a colormap

[X, Y] = meshgrid(-3:0.2:3, -3:0.2:3);
Z = cos(X) .* sin(Y);
contourf(X, Y, Z, [-0.75 -0.25 0 0.25 0.75]);
colormap('turbo');

Inspect the returned contour-fill handle

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

Expected output:

ans =
    'contour'

Filled scalar field with explicit levels

[X, Y] = meshgrid(linspace(-3, 3, 150), linspace(-3, 3, 150));
Z = sin(X) .* cos(Y) + 0.5*sin(2*X + Y);

contourf(X, Y, Z, 25);
colormap('turbo');
colorbar;
title('Interference Pattern — Filled Contours');
xlabel('x');
ylabel('y');
axis equal;
Expected output:
Filled scalar field with explicit levels

Using contourf with coding agents

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

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

FAQ

What's the difference between contourf and contour?

contourf fills the regions between contour levels with solid colors from the colormap. contour draws only the boundary lines. If you're building a heatmap-style visualization where color bands carry meaning, contourf is the right choice. If you just need iso-lines overlaid on something else, use contour.

How does the colormap interact with contourf?

Each filled region maps to a range in the active colormap based on its contour level. Calling colormap('hot') after contourf recolors all regions immediately. Pair it with colorbar to show the value-to-color mapping.

contourf(X, Y, Z, 15);
colormap('hot');
colorbar;
How do I control the number of filled levels?

Pass an integer as the fourth argument to set the level count: contourf(X, Y, Z, 20) creates 20 levels. For exact control, pass a vector of level values instead: contourf(X, Y, Z, [-1 -0.5 0 0.5 1]). More levels give smoother color transitions but add rendering cost on large grids.

2D Charts

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

3D & Surface

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

More plotting resources

Open-source implementation

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