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

Skip to content

Commit 756eb1e

Browse files
committed
Support only positional args for data in contour
1 parent cd8420a commit 756eb1e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/matplotlib/contour.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,7 @@ def _process_args(self, *args, corner_mask=None, algorithm=None, **kwargs):
13861386
"""
13871387
Process args and kwargs.
13881388
"""
1389-
if isinstance(args[0], QuadContourSet):
1389+
if args and isinstance(args[0], QuadContourSet):
13901390
if self.levels is None:
13911391
self.levels = args[0].levels
13921392
self.zmin = args[0].zmin
@@ -1446,11 +1446,11 @@ def _contour_args(self, args, kwargs):
14461446
else:
14471447
fn = 'contour'
14481448
nargs = len(args)
1449-
if nargs <= 2:
1449+
if 0 < nargs <= 2:
14501450
z = ma.asarray(args[0], dtype=np.float64)
14511451
x, y = self._initialize_x_y(z)
14521452
args = args[1:]
1453-
elif nargs <= 4:
1453+
elif 2 < nargs <= 4:
14541454
x, y, z = self._check_xyz(args[:3], kwargs)
14551455
args = args[3:]
14561456
else:

lib/matplotlib/tests/test_contour.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,3 +693,10 @@ def test_contour_remove():
693693
assert ax.get_children() != orig_children
694694
cs.remove()
695695
assert ax.get_children() == orig_children
696+
697+
698+
def test_contour_no_args():
699+
fig, ax = plt.subplots()
700+
data = [[0, 1], [1, 0]]
701+
with pytest.raises(TypeError, match=r"contour\(\) takes from 1 to 4"):
702+
ax.contour(Z=data)

0 commit comments

Comments
 (0)