From 98dd012d90e62b473737276a972a98b6d00ab1fe Mon Sep 17 00:00:00 2001 From: vivekvedant Date: Sun, 22 Jan 2023 23:25:59 +0530 Subject: [PATCH 1/4] fix for pcolormesh doesn't allow shading = 'flat' in the option --- lib/matplotlib/axes/_axes.py | 2 +- lib/matplotlib/tests/test_axes.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index d1e5133ce1d4..e2e87b6f0fea 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -5749,7 +5749,7 @@ def _pcolorargs(self, funcname, *args, shading='auto', **kwargs): if shading == 'flat': if (Nx, Ny) != (ncols + 1, nrows + 1): raise TypeError('Dimensions of C %s are incompatible with' - ' X (%d) and/or Y (%d); see help(%s)' % ( + ' X (%d) and/or Y (%d); X and y should be one larger than C see help(%s)' % ( C.shape, Nx, Ny, funcname)) else: # ['nearest', 'gouraud']: if (Nx, Ny) != (ncols, nrows): diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 8444116b4eb3..0bc4db32a12c 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -1438,6 +1438,13 @@ def test_pcolorflaterror(): with pytest.raises(TypeError, match='Dimensions of C'): ax.pcolormesh(x, y, Z, shading='flat') +def test_samesizepcolorflaterror(): + fig, ax = plt.subplots() + x, y = np.meshgrid(np.arange(5), np.arange(3)) + Z = x + y + with pytest.raises(TypeError, match=r".*X and y should be one larger than C"): + ax.pcolormesh(x, y, Z, shading='flat') + @pytest.mark.parametrize('snap', [False, True]) @check_figures_equal(extensions=["png"]) From 8829e7ed56e57c16cfdc17c41306fabce928ad76 Mon Sep 17 00:00:00 2001 From: vivekvedant Date: Mon, 23 Jan 2023 22:55:36 +0530 Subject: [PATCH 2/4] fix for flake8 --- lib/matplotlib/axes/_axes.py | 6 +++--- lib/matplotlib/tests/test_axes.py | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index e2e87b6f0fea..cc7819923609 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -5748,9 +5748,9 @@ def _pcolorargs(self, funcname, *args, shading='auto', **kwargs): if shading == 'flat': if (Nx, Ny) != (ncols + 1, nrows + 1): - raise TypeError('Dimensions of C %s are incompatible with' - ' X (%d) and/or Y (%d); X and y should be one larger than C see help(%s)' % ( - C.shape, Nx, Ny, funcname)) + raise TypeError(f"Dimensions of X({Nx}) and y({Ny}) should" + f"be one larger than C{C.shape}" + f"see help({funcname})") else: # ['nearest', 'gouraud']: if (Nx, Ny) != (ncols, nrows): raise TypeError('Dimensions of C %s are incompatible with' diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 0bc4db32a12c..611394b5b116 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -1438,11 +1438,12 @@ def test_pcolorflaterror(): with pytest.raises(TypeError, match='Dimensions of C'): ax.pcolormesh(x, y, Z, shading='flat') + def test_samesizepcolorflaterror(): fig, ax = plt.subplots() x, y = np.meshgrid(np.arange(5), np.arange(3)) Z = x + y - with pytest.raises(TypeError, match=r".*X and y should be one larger than C"): + with pytest.raises(TypeError, match=r".*one larger than C"): ax.pcolormesh(x, y, Z, shading='flat') From 04f0dc15403e62d27d72ea97784e13a836ea4f52 Mon Sep 17 00:00:00 2001 From: vivekvedant Date: Mon, 23 Jan 2023 23:05:55 +0530 Subject: [PATCH 3/4] update error message for shading=flat --- lib/matplotlib/axes/_axes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index cc7819923609..c70e254b5dae 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -5749,8 +5749,8 @@ def _pcolorargs(self, funcname, *args, shading='auto', **kwargs): if shading == 'flat': if (Nx, Ny) != (ncols + 1, nrows + 1): raise TypeError(f"Dimensions of X({Nx}) and y({Ny}) should" - f"be one larger than C{C.shape}" - f"see help({funcname})") + f" be one larger than C {C.shape} while using" + f" shading='flat' see help({funcname})") else: # ['nearest', 'gouraud']: if (Nx, Ny) != (ncols, nrows): raise TypeError('Dimensions of C %s are incompatible with' From ad06d939f17e8ad4621b956ba8730d5a1333b01e Mon Sep 17 00:00:00 2001 From: vivekvedant Date: Tue, 24 Jan 2023 16:13:02 +0530 Subject: [PATCH 4/4] changes for fixing the failing test --- lib/matplotlib/axes/_axes.py | 7 ++++--- lib/matplotlib/tests/test_axes.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index c70e254b5dae..1d6516c83b77 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -5748,9 +5748,10 @@ def _pcolorargs(self, funcname, *args, shading='auto', **kwargs): if shading == 'flat': if (Nx, Ny) != (ncols + 1, nrows + 1): - raise TypeError(f"Dimensions of X({Nx}) and y({Ny}) should" - f" be one larger than C {C.shape} while using" - f" shading='flat' see help({funcname})") + raise TypeError(f"Dimensions of C {C.shape} should" + f" be one smaller than X({Nx}) and Y({Ny})" + f" while using shading='flat'" + f" see help({funcname})") else: # ['nearest', 'gouraud']: if (Nx, Ny) != (ncols, nrows): raise TypeError('Dimensions of C %s are incompatible with' diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 611394b5b116..b12b5d0bab46 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -1443,7 +1443,7 @@ def test_samesizepcolorflaterror(): fig, ax = plt.subplots() x, y = np.meshgrid(np.arange(5), np.arange(3)) Z = x + y - with pytest.raises(TypeError, match=r".*one larger than C"): + with pytest.raises(TypeError, match=r".*one smaller than X"): ax.pcolormesh(x, y, Z, shading='flat')