contourpy#
- class contourpy.FillType#
Enum used for
fill_type
keyword argument incontour_generator()
.This controls the format of filled contour data returned from
filled()
.Members:
OuterCode
OuterOffset
ChunkCombinedCode
ChunkCombinedOffset
ChunkCombinedCodeOffset
ChunkCombinedOffsetOffset
- class contourpy.LineType#
Enum used for
line_type
keyword argument incontour_generator()
.This controls the format of contour line data returned from
lines()
.Members:
Separate
SeparateCode
ChunkCombinedCode
ChunkCombinedOffset
- class contourpy.ZInterp#
Enum used for
z_interp
keyword argument incontour_generator()
This controls the interpolation used on
z
values to determine where contour lines intersect the edges of grid quads, andz
values at quad centres.Members:
Linear
Log
- contourpy.contour_generator(x=None, y=None, z=None, *, name='serial', corner_mask=None, line_type=None, fill_type=None, chunk_size=None, chunk_count=None, total_chunk_count=None, quad_as_tri=False, z_interp=<ZInterp.Linear: 1>, thread_count=0)[source]#
Create and return a contour generator object.
The class and properties of the contour generator are determined by the function arguments, with sensible defaults.
- Parameters:
x (array-like of shape (ny, nx) or (nx,), optional) – The x-coordinates of the
z
values. May be 2D with the same shape asz.shape
, or 1D with lengthnx = z.shape[1]
. If not specified are assumed to benp.arange(nx)
. Must be ordered monotonically.y (array-like of shape (ny, nx) or (ny,), optional) – The y-coordinates of the
z
values. May be 2D with the same shape asz.shape
, or 1D with lengthny = z.shape[0]
. If not specified are assumed to benp.arange(ny)
. Must be ordered monotonically.z (array-like of shape (ny, nx), may be a masked array) – The 2D gridded values to calculate the contours of. May be a masked array, and any invalid values (
np.inf
ornp.nan
) will also be masked out.name (str) – Algorithm name, one of
"serial"
,"threaded"
,"mpl2005"
or"mpl2014"
, default"serial"
.corner_mask (bool, optional) – Enable/disable corner masking, which only has an effect if
z
is a masked array. IfFalse
, any quad touching a masked point is masked out. IfTrue
, only the triangular corners of quads nearest these points are always masked out, other triangular corners comprising three unmasked points are contoured as usual. If not specified, uses the default provided by the algorithmname
.line_type (LineType, optional) – The format of contour line data returned from calls to
lines()
. If not specified, uses the default provided by the algorithmname
.fill_type (FillType, optional) – The format of filled contour data returned from calls to
filled()
. If not specified, uses the default provided by the algorithmname
.chunk_size (int or tuple(int, int), optional) – Chunk size in (y, x) directions, or the same size in both directions if only one value is specified.
chunk_count (int or tuple(int, int), optional) – Chunk count in (y, x) directions, or the same count in both directions if only one value is specified.
total_chunk_count (int, optional) – Total number of chunks.
quad_as_tri (bool) – Enable/disable treating quads as 4 triangles, default
False
. IfFalse
, a contour line within a quad is a straight line between points on two of its edges. IfTrue
, each full quad is divided into 4 triangles using a virtual point at the centre (mean x, y of the corner points) and a contour line is piecewise linear within those triangles. Corner-masked triangles are not affected by this setting, only full unmasked quads.z_interp (ZInterp) – How to interpolate
z
values when determining where contour lines intersect the edges of quads and thez
values of the central points of quads, defaultZInterp.Linear
.thread_count (int) – Number of threads to use for contour calculation, default 0. Threads can only be used with an algorithm
name
that supports threads (currently onlyname="threaded"
) and there must be at least the same number of chunks as threads. Ifthread_count=0
andname="threaded"
then it uses the maximum number of threads as determined by the C++11 callstd::thread::hardware_concurrency()
. Ifname
is something other than"threaded"
then thethread_count
will be set to1
.
- Returns:
Note
A maximum of one of
chunk_size
,chunk_count
andtotal_chunk_count
may be specified.Warning
The
name="mpl2005"
algorithm does not implement chunking for contour lines.
- contourpy.max_threads() int #
Return the maximum number of threads, obtained from
std::thread::hardware_concurrency()
.This is the number of threads used by a multithreaded ContourGenerator if the kwarg
threads=0
is passed tocontour_generator()
.
- 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: object, 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.
upper_level (float) – Upper z-level of the filled contours.
- Returns:
Filled contour polygons as one or more sequences of numpy arrays. The exact format is determined by the
fill_type
used by theContourGenerator
.
- property line_type#
Return the
LineType
.
- lines(self: object, level: float) tuple #
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 one or more sequences of numpy arrays. The exact format is determined by the
line_type
used by theContourGenerator
.
- 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 thanZInterp.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
orz_interp
. Only supportsline_type=LineType.SeparateCode
andfill_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 supportscorner_mask
, does not supportquad_as_tri
,threads
orz_interp
. Only supportsline_type=LineType.SeparateCode
andfill_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 forcontourpy
.Supports
corner_mask
,quad_as_tri
andz_interp
but notthreads
. Supports all options forline_type
andfill_type
.
- class contourpy.ThreadedContourGenerator#
Bases:
ContourGenerator
ContourGenerator corresponding to
name="threaded"
, the multithreaded version ofSerialContourGenerator
.Supports
corner_mask
,quad_as_tri
andz_interp
andthreads
. Supports all options forline_type
andfill_type
.