Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6ee6793

Browse filesBrowse files
authored
Merge pull request #24749 from chahak13/24743_contour_kwargs
Support only positional args in contour. Error if no positional argument.
2 parents 2329fd4 + d5baa19 commit 6ee6793
Copy full SHA for 6ee6793

File tree

Expand file treeCollapse file tree

2 files changed

+12
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-3
lines changed

‎lib/matplotlib/contour.py

Copy file name to clipboardExpand all lines: lib/matplotlib/contour.py
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ def _process_args(self, *args, corner_mask=None, algorithm=None, **kwargs):
13811381
"""
13821382
Process args and kwargs.
13831383
"""
1384-
if isinstance(args[0], QuadContourSet):
1384+
if args and isinstance(args[0], QuadContourSet):
13851385
if self.levels is None:
13861386
self.levels = args[0].levels
13871387
self.zmin = args[0].zmin
@@ -1441,13 +1441,15 @@ def _contour_args(self, args, kwargs):
14411441
else:
14421442
fn = 'contour'
14431443
nargs = len(args)
1444-
if nargs <= 2:
1444+
1445+
if 0 < nargs <= 2:
14451446
z, *args = args
14461447
z = ma.asarray(z)
14471448
x, y = self._initialize_x_y(z)
1448-
elif nargs <= 4:
1449+
elif 2 < nargs <= 4:
14491450
x, y, z_orig, *args = args
14501451
x, y, z = self._check_xyz(x, y, z_orig, kwargs)
1452+
14511453
else:
14521454
raise _api.nargs_error(fn, takes="from 1 to 4", given=nargs)
14531455
z = ma.masked_invalid(z, copy=False)

‎lib/matplotlib/tests/test_contour.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_contour.py
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,13 @@ def test_contour_remove():
693693
assert ax.get_children() == orig_children
694694

695695

696+
def test_contour_no_args():
697+
fig, ax = plt.subplots()
698+
data = [[0, 1], [1, 0]]
699+
with pytest.raises(TypeError, match=r"contour\(\) takes from 1 to 4"):
700+
ax.contour(Z=data)
701+
702+
696703
def test_bool_autolevel():
697704
x, y = np.random.rand(2, 9)
698705
z = (np.arange(9) % 2).reshape((3, 3)).astype(bool)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.