Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ def _process_args(self, *args, corner_mask=None, algorithm=None, **kwargs):
"""
Process args and kwargs.
"""
if isinstance(args[0], QuadContourSet):
if args and isinstance(args[0], QuadContourSet):
if self.levels is None:
self.levels = args[0].levels
self.zmin = args[0].zmin
Expand Down Expand Up @@ -1441,13 +1441,15 @@ def _contour_args(self, args, kwargs):
else:
fn = 'contour'
nargs = len(args)
if nargs <= 2:

if 0 < nargs <= 2:
z, *args = args
z = ma.asarray(z)
x, y = self._initialize_x_y(z)
elif nargs <= 4:
elif 2 < nargs <= 4:
x, y, z_orig, *args = args
x, y, z = self._check_xyz(x, y, z_orig, kwargs)

else:
raise _api.nargs_error(fn, takes="from 1 to 4", given=nargs)
z = ma.masked_invalid(z, copy=False)
Expand Down
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,13 @@ def test_contour_remove():
assert ax.get_children() == orig_children


def test_contour_no_args():
fig, ax = plt.subplots()
data = [[0, 1], [1, 0]]
with pytest.raises(TypeError, match=r"contour\(\) takes from 1 to 4"):
ax.contour(Z=data)


def test_bool_autolevel():
x, y = np.random.rand(2, 9)
z = (np.arange(9) % 2).reshape((3, 3)).astype(bool)
Expand Down