The problem
plt.contour, contourpy, skimage.measure.find_contours: the scientific
Python stack has several contouring entry points, and on megapixel grids with
dozens of levels each one becomes the slowest line in the notebook. It is too
slow for a slider, too slow for animation, and painful inside a batch loop over
thousands of fields. ContourPy’s
threaded mode
helps if you have spare cores, but it splits lines at chunk boundaries.
Head-to-head (what you’d call from Python)
matplotlib’s contour() computes its lines with ContourPy, so ContourPy is
benchmarked directly, in its fastest modes. matplotlib itself adds plotting
objects on top, which isn’t contour computation. Every tool below is called from
Python on the same numpy array and returns geometry. isosweep is timed through its Python package, including the
float64→float32 conversion and the construction of the returned curve objects.
| Dataset | Grid · levels | isosweep1 thread | isosweep16 threads | ContourPy1 thread | scikit-image find_contours1 thread | VTK Flying Edges1 thread | ContourPy64 threads | VTK Flying Edges8 threads | Speed-upvs fastest 1-thread | Speed-upvs fastest overall |
|---|---|---|---|---|---|---|---|---|---|---|
| Interactive 60fps level scrubbing | 1,024 × 1,024 · 25 | 14.0 ms | 3.18 ms | 112 ms | 297 ms | 93.9 ms | 25.7 ms | 36.3 ms | 6.7× | 8.1× |
| HRRR temperature frontal analysis | 1,799 × 1,799 · 26 levels (interval 2.5) | 6.34 ms | 1.70 ms | 302 ms | 436 ms | 155 ms | 43.5 ms | 24.0 ms▲ | 24× | 14× |
| Full SRTM 1-degree elevation tile | 3,601 × 3,601 · 25 | 74.2 ms | 6.75 ms | 1.28 s | 2.12 s | 822 ms | 91.0 ms | 106 ms | 11× | 13× |
| OPC line/space process-variation band | 2,048 × 2,048 · 9 | 12.4 ms | 4.73 ms | 157 ms | 253 ms | 152 ms | 18.6 ms | 77.1 ms | 12× | 3.9× |
| Vascular network segmentation | 1,024 × 1,024 · 10 | 2.64 ms | 1.11 ms | 42.8 ms | 73.2 ms | 23.9 ms | 9.77 ms | 6.72 ms | 9.1× | 6.0× |
Median wall-clock time per full extraction, in-process, identical in-memory grid and iso-levels for every tool, each in its fastest documented configuration; lower is better. All line tools return assembled polylines. "Fastest overall" compares our best (1 or 16 threads) with the best result of any other library at any thread count; the shaded cell is that library. Measured November 2026 on Intel(R) Xeon(R) Platinum 8488C (48 cores / 96 threads) — AWS EC2 c7i.metal-24xl (dedicated bare-metal server, no hypervisor); Linux-7.0.0-1018-aws-x86_64-with-glibc2.39; turbo disabled; governor performance; THP never. ▲ marks a time that varied more than 5% from run to run; it is used as measured. Methodology.
Exact configuration of each library
- ContourPy (serial) — variant serial_reused {"name": "serial", "line_type": "LineType.ChunkCombinedOffset", "reuse_generator": true}
- scikit-image find_contours — variant per_level {}
- VTK Flying Edges (1 thread) — vtkImageData + filter pipeline built in prepare (zero-copy wrap, O(1)). vtkStripper joins segments into polylines (required for like-for-like output; MaximumLength unlimited so lines are fully joined) and is timed. variant sequential {"backend": "Sequential", "threads": 1}
- ContourPy (threaded, best threads × chunks) — variant threaded_reused {"name": "threaded", "line_type": "LineType.ChunkCombinedOffset", "thread_count": 8, "chunk_count": [4, 4], "reuse_generator": true}
- VTK Flying Edges (best SMP backend × threads) — vtkImageData + filter pipeline built in prepare (zero-copy wrap, O(1)). vtkStripper joins segments into polylines (required for like-for-like output; MaximumLength unlimited so lines are fully joined) and is timed. variant smp {"backend": "STDThread", "threads": 4}
Drop-in usage
import isocurves
res = isocurves.contour(z, levels=np.linspace(z.min(), z.max(), 25))for c in res: # ordered curves, not segment soup plt.plot(c.x, c.y, lw=0.6) # c.is_closed, c.is_hill, c.level_value- Interactive. A full re-contour of a 1024² grid at 25 levels takes 14.0 ms on one core (ContourPy: 112 ms), so level sliders, time scrubbing and animations stay responsive.
- Topology included. Curves arrive ordered and closed where the field
closes them, with a hill/hole flag. You don’t need
ContourSetinternals to work out which curve is a hole. - Repeatable. The same input and settings give the same output on every run.
MATLAB’s contourc is not benchmarked. Its licence agreement prohibits
benchmarking MATLAB for the purpose of building software with similar functions.