ContourGenerator#

class contourpy.ContourGenerator#

Abstract base class for contour generator classes, defining the interface that they all implement.

class property default_fill_type#

Return the default FillType used by this algorithm.

class property default_line_type#

Return the default LineType used by this algorithm.

property chunk_count#

Return tuple of (y, x) chunk counts.

property chunk_size#

Return tuple of (y, x) chunk sizes.

property corner_mask#

Return whether corner_mask is set or not.

property fill_type#

Return the FillType.

filled(self: contourpy._contourpy.ContourGenerator, lower_level: float, upper_level: float) tuple#

Calculate and return filled contours between two levels.

Parameters:
  • lower_level (float) – Lower z-level of the filled contours, cannot be np.nan.

  • upper_level (float) – Upper z-level of the filled contours, cannot be np.nan.

Returns:

Filled contour polygons as nested sequences of numpy arrays. The exact format is determined by the fill_type used by the ContourGenerator and the options are explained at Fill type.

Raises a ValueError if lower_level >= upper_level or if lower_level or upper_level are np.nan.

To return filled contours below a level use filled(-np.inf, level). To return filled contours above a level use filled(level, np.inf)

property line_type#

Return the LineType.

lines(self: contourpy._contourpy.ContourGenerator, level: float) Sequence#

Calculate and return contour lines at a particular level.

Parameters:

level (float) – z-level to calculate contours at.

Returns:

Contour lines (open line strips and closed line loops) as nested sequences of numpy arrays. The exact format is determined by the line_type used by the ContourGenerator and the options are explained at Line type.

level may be np.nan, np.inf or -np.inf; they all return the same result which is an empty line set.

multi_filled(self: contourpy._contourpy.ContourGenerator, levels: numpy.ndarray[numpy.float64]) list#

Calculate and return filled contours between multiple levels.

Parameters:

levels (array-like of floats) – z-levels to calculate filled contours between. There must be at least 2 levels, they cannot be NaN, and each level must be larger than the previous level.

Returns:

List of filled contours, one per pair of levels. The length of the returned list is one less than len(levels). The format of returned contours is determined by the fill_type used by the ContourGenerator.

Raises a ValueError if levels are not increasing, or contain a NaN, or there are fewer than 2 levels.

Calling:

ret = obj.multi_filled(levels)

is equivalent to:

ret = [obj.filled(lower, upper) for lower, upper in zip(levels[:-1], levels[1:])]

New in version 1.3.0.

multi_lines(self: contourpy._contourpy.ContourGenerator, levels: numpy.ndarray[numpy.float64]) list#

Calculate and return contour lines at multiple levels.

Parameters:

levels (array-like of floats) – z-levels to calculate contours at.

Returns:

List of contour lines, one per level. The format of returned lines is determined by the line_type used by the ContourGenerator.

Calling:

ret = obj.multi_lines(levels)

is equivalent to:

ret = [obj.lines(level) for level in levels]

New in version 1.3.0.

property quad_as_tri#

Return whether quad_as_tri is set or not.

static supports_corner_mask() bool#

Return whether this algorithm supports corner_mask.

static supports_fill_type(fill_type: contourpy._contourpy.FillType) bool#

Return whether this algorithm supports a particular FillType.

static supports_line_type(line_type: contourpy._contourpy.LineType) bool#

Return whether this algorithm supports a particular LineType.

static supports_quad_as_tri() bool#

Return whether this algorithm supports quad_as_tri.

static supports_threads() bool#

Return whether this algorithm supports the use of threads.

static supports_z_interp() bool#

Return whether this algorithm supports z_interp values other than ZInterp.Linear which all support.

property thread_count#

Return the number of threads used.

property z_interp#

Return the ZInterp.

class contourpy.Mpl2005ContourGenerator#

Bases: ContourGenerator

ContourGenerator corresponding to name="mpl2005".

This is the original 2005 Matplotlib algorithm. Does not support any of corner_mask, quad_as_tri, threads or z_interp. Only supports line_type=LineType.SeparateCode and fill_type=FillType.OuterCode. Only supports chunking for filled contours, not contour lines.

Warning

This algorithm is in contourpy for historic comparison. No new features or bug fixes will be added to it, except for security-related bug fixes.

class contourpy.Mpl2014ContourGenerator#

Bases: ContourGenerator

ContourGenerator corresponding to name="mpl2014".

This is the 2014 Matplotlib algorithm, a replacement of the original 2005 algorithm that added corner_mask and made the code more maintainable. Only supports corner_mask, does not support quad_as_tri, threads or z_interp. Only supports line_type=LineType.SeparateCode and fill_type=FillType.OuterCode.

Warning

This algorithm is in contourpy for historic comparison. No new features or bug fixes will be added to it, except for security-related bug fixes.

class contourpy.SerialContourGenerator#

Bases: ContourGenerator

ContourGenerator corresponding to name="serial", the default algorithm for contourpy.

Supports corner_mask, quad_as_tri and z_interp but not threads. Supports all options for line_type and fill_type.

class contourpy.ThreadedContourGenerator#

Bases: ContourGenerator

ContourGenerator corresponding to name="threaded", the multithreaded version of SerialContourGenerator.

Supports corner_mask, quad_as_tri and z_interp and threads. Supports all options for line_type and fill_type.