Skip to content

Commit e95572c

Browse files
committed
Remove legacy contouring.
1 parent f96fac0 commit e95572c

File tree

6 files changed

+16
-2114
lines changed

6 files changed

+16
-2114
lines changed

lib/matplotlib/contour.py

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import matplotlib as mpl
1212
import numpy as np
1313
from numpy import ma
14-
import matplotlib._cntr as _cntr
1514
import matplotlib._contour as _contour
1615
import matplotlib.path as mpath
1716
import matplotlib.ticker as ticker
@@ -1171,10 +1170,7 @@ def _contour_level_args(self, z, args):
11711170
raise ValueError("Filled contours require at least 2 levels.")
11721171

11731172
if len(self.levels) > 1 and np.min(np.diff(self.levels)) <= 0.0:
1174-
if hasattr(self, '_corner_mask') and self._corner_mask == 'legacy':
1175-
warnings.warn("Contour levels are not increasing")
1176-
else:
1177-
raise ValueError("Contour levels must be increasing")
1173+
raise ValueError("Contour levels must be increasing")
11781174

11791175
@property
11801176
def vmin(self):
@@ -1419,10 +1415,7 @@ def _process_args(self, *args, **kwargs):
14191415
self.zmin = args[0].zmin
14201416
self.zmax = args[0].zmax
14211417
self._corner_mask = args[0]._corner_mask
1422-
if self._corner_mask == 'legacy':
1423-
contour_generator = args[0].Cntr
1424-
else:
1425-
contour_generator = args[0]._contour_generator
1418+
contour_generator = args[0]._contour_generator
14261419
self._mins = args[0]._mins
14271420
self._maxs = args[0]._maxs
14281421
else:
@@ -1436,14 +1429,8 @@ def _process_args(self, *args, **kwargs):
14361429
if _mask is ma.nomask or not _mask.any():
14371430
_mask = None
14381431

1439-
if self._corner_mask == 'legacy':
1440-
cbook.warn_deprecated('1.5',
1441-
name="corner_mask='legacy'",
1442-
alternative='corner_mask=False or True')
1443-
contour_generator = _cntr.Cntr(x, y, z.filled(), _mask)
1444-
else:
1445-
contour_generator = _contour.QuadContourGenerator(
1446-
x, y, z.filled(), _mask, self._corner_mask, self.nchunk)
1432+
contour_generator = _contour.QuadContourGenerator(
1433+
x, y, z.filled(), _mask, self._corner_mask, self.nchunk)
14471434

14481435
t = self.get_transform()
14491436

@@ -1460,43 +1447,26 @@ def _process_args(self, *args, **kwargs):
14601447
self._mins = [ma.min(x), ma.min(y)]
14611448
self._maxs = [ma.max(x), ma.max(y)]
14621449

1463-
if self._corner_mask == 'legacy':
1464-
self.Cntr = contour_generator
1465-
else:
1466-
self._contour_generator = contour_generator
1450+
self._contour_generator = contour_generator
14671451

14681452
return kwargs
14691453

14701454
def _get_allsegs_and_allkinds(self):
1471-
"""
1472-
Create and return allsegs and allkinds by calling underlying C code.
1473-
"""
1455+
"""Compute ``allsegs`` and ``allkinds`` using C extension."""
14741456
allsegs = []
14751457
if self.filled:
14761458
lowers, uppers = self._get_lowers_and_uppers()
14771459
allkinds = []
14781460
for level, level_upper in zip(lowers, uppers):
1479-
if self._corner_mask == 'legacy':
1480-
nlist = self.Cntr.trace(level, level_upper,
1481-
nchunk=self.nchunk)
1482-
nseg = len(nlist) // 2
1483-
vertices = nlist[:nseg]
1484-
kinds = nlist[nseg:]
1485-
else:
1486-
vertices, kinds = \
1487-
self._contour_generator.create_filled_contour(
1488-
level, level_upper)
1461+
vertices, kinds = \
1462+
self._contour_generator.create_filled_contour(
1463+
level, level_upper)
14891464
allsegs.append(vertices)
14901465
allkinds.append(kinds)
14911466
else:
14921467
allkinds = None
14931468
for level in self.levels:
1494-
if self._corner_mask == 'legacy':
1495-
nlist = self.Cntr.trace(level)
1496-
nseg = len(nlist) // 2
1497-
vertices = nlist[:nseg]
1498-
else:
1499-
vertices = self._contour_generator.create_contour(level)
1469+
vertices = self._contour_generator.create_contour(level)
15001470
allsegs.append(vertices)
15011471
return allsegs, allkinds
15021472

@@ -1687,19 +1657,15 @@ def _initialize_x_y(self, z):
16871657
16881658
Optional keyword arguments:
16891659
1690-
*corner_mask*: [ *True* | *False* | 'legacy' ]
1660+
*corner_mask*: bool, optional
16911661
Enable/disable corner masking, which only has an effect if *Z* is
1692-
a masked array. If *False*, any quad touching a masked point is
1693-
masked out. If *True*, only the triangular corners of quads
1662+
a masked array. If ``False``, any quad touching a masked point is
1663+
masked out. If ``True``, only the triangular corners of quads
16941664
nearest those points are always masked out, other triangular
16951665
corners comprising three unmasked points are contoured as usual.
1696-
If 'legacy', the old contouring algorithm is used, which is
1697-
equivalent to *False* and is deprecated, only remaining whilst the
1698-
new algorithm is tested fully.
16991666
1700-
If not specified, the default is taken from
1701-
rcParams['contour.corner_mask'], which is True unless it has
1702-
been modified.
1667+
Defaults to ``rcParams['contour.corner_mask']``, which defaults to
1668+
``True``.
17031669
17041670
*colors*: [ *None* | string | (mpl_colors) ]
17051671
If *None*, the colormap specified by cmap will be used.

lib/matplotlib/rcsetup.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,6 @@ def validate_negative_linestyle_legacy(s):
548548
return (0, dashes) # (offset, (solid, blank))
549549

550550

551-
def validate_corner_mask(s):
552-
if s == 'legacy':
553-
return s
554-
else:
555-
return validate_bool(s)
556-
557-
558551
validate_legend_loc = ValidateInStrings(
559552
'legend_loc',
560553
['best',
@@ -1097,7 +1090,7 @@ def _validate_linestyle(ls):
10971090

10981091
# contour props
10991092
'contour.negative_linestyle': ['dashed', _validate_linestyle],
1100-
'contour.corner_mask': [True, validate_corner_mask],
1093+
'contour.corner_mask': [True, validate_bool],
11011094

11021095
# errorbar props
11031096
'errorbar.capsize': [0, validate_float],

lib/matplotlib/tests/test_contour.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,6 @@ def test_contourf_decreasing_levels():
303303
plt.figure()
304304
with pytest.raises(ValueError):
305305
plt.contourf(z, [1.0, 0.0])
306-
# Legacy contouring algorithm gives a warning rather than raising an error,
307-
# plus a DeprecationWarning.
308-
with warnings.catch_warnings(record=True) as w:
309-
warnings.simplefilter("always")
310-
plt.contourf(z, [1.0, 0.0], corner_mask='legacy')
311-
assert len(w) == 2
312306

313307

314308
def test_vminvmax_warning():

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
setupext.Image(),
6767
setupext.TTConv(),
6868
setupext.Path(),
69-
setupext.ContourLegacy(),
7069
setupext.Contour(),
7170
setupext.QhullWrap(),
7271
setupext.Tri(),

setupext.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,18 +1408,6 @@ def get_extension(self):
14081408
return ext
14091409

14101410

1411-
class ContourLegacy(SetupPackage):
1412-
name = "contour_legacy"
1413-
1414-
def get_extension(self):
1415-
sources = [
1416-
"src/cntr.c"
1417-
]
1418-
ext = make_extension('matplotlib._cntr', sources)
1419-
Numpy().add_flags(ext)
1420-
return ext
1421-
1422-
14231411
class Contour(SetupPackage):
14241412
name = "contour"
14251413

0 commit comments

Comments
 (0)