Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4c62289

Browse files
committed
Legacy contouring only warns if levels decreasing
1 parent e162e88 commit 4c62289

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

lib/matplotlib/contour.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,8 +1191,12 @@ def _contour_level_args(self, z, args):
11911191
self.levels = lev
11921192
if self.filled and len(self.levels) < 2:
11931193
raise ValueError("Filled contours require at least 2 levels.")
1194+
11941195
if len(self.levels) > 1 and np.amin(np.diff(self.levels)) <= 0.0:
1195-
raise ValueError("Contour levels must be increasing")
1196+
if hasattr(self, '_corner_mask') and self._corner_mask == 'legacy':
1197+
warnings.warn("Contour levels are not increasing")
1198+
else:
1199+
raise ValueError("Contour levels must be increasing")
11961200

11971201
def _process_levels(self):
11981202
"""
@@ -1444,16 +1448,16 @@ def _process_args(self, *args, **kwargs):
14441448
else:
14451449
contour_generator = args[0]._contour_generator
14461450
else:
1451+
self._corner_mask = kwargs.get('corner_mask', None)
1452+
if self._corner_mask is None:
1453+
self._corner_mask = mpl.rcParams['contour.corner_mask']
1454+
14471455
x, y, z = self._contour_args(args, kwargs)
14481456

14491457
_mask = ma.getmask(z)
14501458
if _mask is ma.nomask or not _mask.any():
14511459
_mask = None
14521460

1453-
self._corner_mask = kwargs.get('corner_mask', None)
1454-
if self._corner_mask is None:
1455-
self._corner_mask = mpl.rcParams['contour.corner_mask']
1456-
14571461
if self._corner_mask == 'legacy':
14581462
cbook.warn_deprecated('1.5',
14591463
name="corner_mask='legacy'",

lib/matplotlib/tests/test_contour.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from matplotlib import mlab
1010
from matplotlib.testing.decorators import cleanup, image_comparison
1111
from matplotlib import pyplot as plt
12-
from nose.tools import assert_raises
12+
from nose.tools import assert_equal, assert_raises
13+
import warnings
1314

1415
import re
1516

@@ -271,6 +272,11 @@ def test_contourf_decreasing_levels():
271272
z = [[0.1, 0.3], [0.5, 0.7]]
272273
plt.figure()
273274
assert_raises(ValueError, plt.contourf, z, [1.0, 0.0])
275+
# Legacy contouring algorithm gives a warning rather than raising an error,
276+
# plus a DeprecationWarning.
277+
with warnings.catch_warnings(record=True) as w:
278+
plt.contourf(z, [1.0, 0.0], corner_mask='legacy')
279+
assert_equal(len(w), 2)
274280

275281

276282
if __name__ == '__main__':

0 commit comments

Comments
 (0)