contour_generator¶
- 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
ContourGeneratorobject.The class and properties of the returned
ContourGeneratorare determined by the function arguments, with sensible defaults.- Parameters:
x (array-like of shape (ny, nx) or (nx,), optional) – The x-coordinates of the
zvalues. 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
zvalues. 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.infornp.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
zis 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 or str, optional) – The format of contour line data returned from calls to
lines(), specified either as aLineTypeor its string equivalent such as"SeparateCode". If not specified, uses the default provided by the algorithmname. The relationship between theLineTypeenum and the data format returned fromlines()is explained at Line type.fill_type (FillType or str, optional) – The format of filled contour data returned from calls to
filled(), specified either as aFillTypeor its string equivalent such as"OuterOffset". If not specified, uses the default provided by the algorithmname. The relationship between theFillTypeenum and the data format returned fromfilled()is explained at Fill type.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 or str, optional) – How to interpolate
zvalues when determining where contour lines intersect the edges of quads and thezvalues of the central points of quads, specified either as aZInterpor its string equivalent such as"Log". Default isZInterp.Linear.thread_count (int) – Number of threads to use for contour calculation, default 0. Threads can only be used with an algorithm
namethat supports threads (currently onlyname="threaded") and there must be at least the same number of chunks as threads. Ifthread_count=0andname="threaded"then it uses the maximum number of threads as determined by the C++11 callstd::thread::hardware_concurrency(). Ifnameis something other than"threaded"then thethread_countwill be set to1.
- Returns:
Note
A maximum of one of
chunk_size,chunk_countandtotal_chunk_countmay be specified.Warning
The
name="mpl2005"algorithm does not implement chunking for contour lines.