From 756eb1e539aff1aa7c9a73c42b527c6b6f204419 Mon Sep 17 00:00:00 2001 From: Chahak Mehta Date: Thu, 22 Dec 2022 12:43:23 +0530 Subject: [PATCH] Support only positional args for data in contour --- lib/matplotlib/contour.py | 6 +++--- lib/matplotlib/tests/test_contour.py | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/contour.py b/lib/matplotlib/contour.py index 144eadeae2c6..de333141157e 100644 --- a/lib/matplotlib/contour.py +++ b/lib/matplotlib/contour.py @@ -1386,7 +1386,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 @@ -1446,11 +1446,11 @@ def _contour_args(self, args, kwargs): else: fn = 'contour' nargs = len(args) - if nargs <= 2: + if 0 < nargs <= 2: z = ma.asarray(args[0], dtype=np.float64) x, y = self._initialize_x_y(z) args = args[1:] - elif nargs <= 4: + elif 2 < nargs <= 4: x, y, z = self._check_xyz(args[:3], kwargs) args = args[3:] else: diff --git a/lib/matplotlib/tests/test_contour.py b/lib/matplotlib/tests/test_contour.py index e42206b8cb79..bd8992b85b0f 100644 --- a/lib/matplotlib/tests/test_contour.py +++ b/lib/matplotlib/tests/test_contour.py @@ -693,3 +693,10 @@ def test_contour_remove(): assert ax.get_children() != orig_children cs.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)