contourf — Create filled contour plots for level regions, scalar fields, and MATLAB contourf workflows.
contourf creates filled contour plots by coloring the regions between contour levels. In RunMat it returns a contour-fill handle, shares the contour level-generation path with contour, and acts as the filled-region counterpart to line-oriented contour plots.
How contourf works
contourf(Z)uses implicit axes, whilecontourf(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.
contourfworks naturally withcolorbarandcolormapbecause 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;
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.
Related Plotting functions
More plotting resources
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how contourf works, line by line, in Rust.
- View contourf.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.