or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

algorithm-classes.mdcontour-generation.mddata-conversion.mdindex.mdtypes-configuration.md
tile.json

tessl/pypi-contourpy

Python library for calculating contours of 2D quadrilateral grids

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/contourpy@1.3.x

To install, run

npx @tessl/cli install tessl/pypi-contourpy@1.3.0

index.mddocs/

ContourPy

ContourPy is a Python library for calculating contours of 2D quadrilateral grids. Written in C++11 and wrapped using pybind11, it provides the 2005 and 2014 algorithms used in Matplotlib as well as newer algorithms available in both serial and multithreaded versions. It enables Python applications to perform efficient contour calculations without requiring Matplotlib as a dependency.

Package Information

  • Package Name: contourpy
  • Language: Python
  • Installation: pip install contourpy

Core Imports

import contourpy

Most common for creating contour generators:

from contourpy import contour_generator

For working with specific algorithms and types:

from contourpy import (
    contour_generator,
    FillType,
    LineType,
    ZInterp,
    ContourGenerator,
    SerialContourGenerator,
    ThreadedContourGenerator,
    __version__
)

For utility functions:

from contourpy.util import build_config

Basic Usage

import contourpy
import numpy as np

# Create sample 2D data
x = np.linspace(-3, 3, 100)
y = np.linspace(-3, 3, 100)
X, Y = np.meshgrid(x, y)
Z = X**2 + Y**2

# Create a contour generator
cont_gen = contourpy.contour_generator(X, Y, Z)

# Generate contour lines at a specific level
lines = cont_gen.lines(4.0)

# Generate filled contours between two levels
filled = cont_gen.filled(2.0, 6.0)

# Generate multiple contour lines at different levels
levels = [1.0, 2.0, 3.0, 4.0, 5.0]
multi_lines = cont_gen.multi_lines(levels)

# Generate multiple filled contours
multi_filled = cont_gen.multi_filled(levels)

Architecture

ContourPy provides multiple algorithm implementations through a unified interface:

  • ContourGenerator: Abstract base class defining the standard interface
  • Algorithm Implementations: Four concrete implementations with different capabilities:
    • Mpl2005ContourGenerator: Legacy Matplotlib 2005 algorithm
    • Mpl2014ContourGenerator: Legacy Matplotlib 2014 algorithm with corner masking
    • SerialContourGenerator: Modern serial algorithm with full feature support
    • ThreadedContourGenerator: Modern multithreaded algorithm for parallel processing
  • Data Formats: Flexible output formats controlled by LineType and FillType enums
  • Processing Options: Chunking support for large datasets and memory management

Capabilities

Contour Generation

Core functionality for creating contour generators and computing contours with multiple algorithm options, output formats, and processing configurations.

def contour_generator(
    x: ArrayLike | None = None,
    y: ArrayLike | None = None,
    z: ArrayLike | np.ma.MaskedArray | None = None,
    *,
    name: str = "serial",
    corner_mask: bool | None = None,
    line_type: LineType | str | None = None,
    fill_type: FillType | str | None = None,
    chunk_size: int | tuple[int, int] | None = None,
    chunk_count: int | tuple[int, int] | None = None,
    total_chunk_count: int | None = None,
    quad_as_tri: bool = False,
    z_interp: ZInterp | str | None = ZInterp.Linear,
    thread_count: int = 0,
) -> ContourGenerator: ...

Contour Generation

Algorithm Classes

Direct access to specific contour generation algorithms with their individual constructors and capabilities.

class ContourGenerator:
    def lines(self, level: float) -> LineReturn: ...
    def filled(self, lower_level: float, upper_level: float) -> FillReturn: ...
    def multi_lines(self, levels) -> list[LineReturn]: ...
    def multi_filled(self, levels) -> list[FillReturn]: ...

class SerialContourGenerator(ContourGenerator): ...
class ThreadedContourGenerator(ContourGenerator): ...
class Mpl2005ContourGenerator(ContourGenerator): ...
class Mpl2014ContourGenerator(ContourGenerator): ...

Algorithm Classes

Data Conversion and Processing

Functions for converting between different contour data formats and processing chunked results.

def convert_filled(filled, fill_type_from: FillType | str, fill_type_to: FillType | str): ...
def convert_lines(lines, line_type_from: LineType | str, line_type_to: LineType | str): ...
def dechunk_filled(filled, fill_type: FillType | str): ...
def dechunk_lines(lines, line_type: LineType | str): ...

Data Conversion

Configuration and Types

Enums for configuring output formats and interpolation methods, plus utility functions.

class FillType:
    OuterCode: FillType
    OuterOffset: FillType
    ChunkCombinedCode: FillType
    ChunkCombinedOffset: FillType
    ChunkCombinedCodeOffset: FillType
    ChunkCombinedOffsetOffset: FillType

class LineType:
    Separate: LineType
    SeparateCode: LineType
    ChunkCombinedCode: LineType
    ChunkCombinedOffset: LineType
    ChunkCombinedNan: LineType

class ZInterp:
    Linear: ZInterp
    Log: ZInterp

def max_threads() -> int: ...

Types and Configuration

Version and Build Information

Package version and build configuration utilities.

__version__: str  # Package version string

# Available in contourpy.util submodule
def build_config() -> dict[str, str]:  # Build configuration details

Types

# Required imports for type definitions
from numpy.typing import ArrayLike, NDArray
import numpy as np

# Input array types
CoordinateArray = NDArray[np.float64]  # For x, y coordinates
MaskArray = NDArray[np.bool_]  # For data masks
LevelArray = ArrayLike  # For contour level specifications

# Output array types
PointArray = NDArray[np.float64]  # Contour point coordinates
CodeArray = NDArray[np.uint8]  # Path codes for matplotlib compatibility
OffsetArray = NDArray[np.uint32]  # Offset arrays for line/polygon segments

# Return types from contour methods
LineReturn = list[PointArray] | tuple[list[PointArray], list[CodeArray]] | tuple[list[PointArray | None], ...]
FillReturn = tuple[list[PointArray], list[CodeArray | OffsetArray]] | tuple[list[PointArray | None], ...]