@@ -1420,7 +1420,7 @@ class QuadContourSet(ContourSet):
14201420 %(contour_set_attributes)s
14211421 """
14221422
1423- def _process_args (self , * args , corner_mask = None , ** kwargs ):
1423+ def _process_args (self , * args , corner_mask = None , algorithm = None , ** kwargs ):
14241424 """
14251425 Process args and kwargs.
14261426 """
@@ -1433,21 +1433,31 @@ def _process_args(self, *args, corner_mask=None, **kwargs):
14331433 contour_generator = args [0 ]._contour_generator
14341434 self ._mins = args [0 ]._mins
14351435 self ._maxs = args [0 ]._maxs
1436+ self ._algorithm = args [0 ]._algorithm
14361437 else :
1437- import matplotlib ._contour as _contour
1438+ import contourpy
1439+
1440+ if algorithm is None :
1441+ algorithm = mpl .rcParams ['contour.algorithm' ]
1442+ mpl .rcParams .validate ["contour.algorithm" ](algorithm )
1443+ self ._algorithm = algorithm
14381444
14391445 if corner_mask is None :
1440- corner_mask = mpl .rcParams ['contour.corner_mask' ]
1446+ if self ._algorithm == "mpl2005" :
1447+ # mpl2005 does not support corner_mask=True so if not
1448+ # specifically requested then disable it.
1449+ corner_mask = False
1450+ else :
1451+ corner_mask = mpl .rcParams ['contour.corner_mask' ]
14411452 self ._corner_mask = corner_mask
14421453
14431454 x , y , z = self ._contour_args (args , kwargs )
14441455
1445- _mask = ma .getmask (z )
1446- if _mask is ma .nomask or not _mask .any ():
1447- _mask = None
1448-
1449- contour_generator = _contour .QuadContourGenerator (
1450- x , y , z .filled (), _mask , self ._corner_mask , self .nchunk )
1456+ contour_generator = contourpy .contour_generator (
1457+ x , y , z , name = self ._algorithm , corner_mask = self ._corner_mask ,
1458+ line_type = contourpy .LineType .SeparateCode ,
1459+ fill_type = contourpy .FillType .OuterCode ,
1460+ chunk_size = self .nchunk )
14511461
14521462 t = self .get_transform ()
14531463
@@ -1772,6 +1782,15 @@ def _initialize_x_y(self, z):
17721782 Hatching is supported in the PostScript, PDF, SVG and Agg
17731783 backends only.
17741784
1785+ algorithm : {'mpl2005', 'mpl2014', 'serial', 'threaded'}, optional
1786+ Which contouring algorithm to use to calculate the contour lines and
1787+ polygons. The algorithms are implemented in
1788+ `ContourPy <https://github.com/contourpy/contourpy>`_, consult the
1789+ `ContourPy documentation <https://contourpy.readthedocs.io>`_ for
1790+ further information.
1791+
1792+ The default is taken from :rc:`contour.algorithm`.
1793+
17751794data : indexable object, optional
17761795 DATA_PARAMETER_PLACEHOLDER
17771796
@@ -1792,5 +1811,5 @@ def _initialize_x_y(self, z):
179218113. `.contour` and `.contourf` use a `marching squares
17931812 <https://en.wikipedia.org/wiki/Marching_squares>`_ algorithm to
17941813 compute contour locations. More information can be found in
1795- the source ``src/_contour.h`` .
1814+ `ContourPy documentation <https://contourpy.readthedocs.io>`_ .
17961815""" )
0 commit comments