diff --git a/doc/api/next_api_changes/behavior/20268-JMK.rst b/doc/api/next_api_changes/behavior/20268-JMK.rst new file mode 100644 index 000000000000..e0ff20bfcc82 --- /dev/null +++ b/doc/api/next_api_changes/behavior/20268-JMK.rst @@ -0,0 +1,11 @@ +pcolor(mesh) shading defaults to auto +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The *shading* kwarg for `.Axes.pcolormesh` and `.Axes.pcolor` default +has been changed to 'auto'. + +Passing ``Z(M, N)``, ``x(N)``, ``y(M)`` to ``pcolormesh`` with +``shading='flat'`` will now raise a ``TypeError``. Use +``shading='auto'`` or ``shading='nearest'`` for ``x`` and ``y`` +to be treated as cell centers, or drop the last column and row +of ``Z`` to get the old behavior with ``shading='flat'``. \ No newline at end of file diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index ee4c2b5e371b..58994cc8c456 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -5603,7 +5603,7 @@ def imshow(self, X, cmap=None, norm=None, aspect=None, self.add_image(im) return im - def _pcolorargs(self, funcname, *args, shading='flat', **kwargs): + def _pcolorargs(self, funcname, *args, shading='auto', **kwargs): # - create X and Y if not present; # - reshape X and Y as needed if they are 1-D; # - check for proper sizes based on `shading` kwarg; @@ -5675,25 +5675,16 @@ def _pcolorargs(self, funcname, *args, shading='flat', **kwargs): shading = 'flat' if shading == 'flat': - if not (ncols in (Nx, Nx - 1) and nrows in (Ny, Ny - 1)): + 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)' % ( C.shape, Nx, Ny, funcname)) - if (ncols == Nx or nrows == Ny): - _api.warn_deprecated( - "3.3", message="shading='flat' when X and Y have the same " - "dimensions as C is deprecated since %(since)s. Either " - "specify the corners of the quadrilaterals with X and Y, " - "or pass shading='auto', 'nearest' or 'gouraud', or set " - "rcParams['pcolor.shading']. This will become an error " - "%(removal)s.") - C = C[:Ny - 1, :Nx - 1] else: # ['nearest', 'gouraud']: if (Nx, Ny) != (ncols, nrows): raise TypeError('Dimensions of C %s are incompatible with' ' X (%d) and/or Y (%d); see help(%s)' % ( C.shape, Nx, Ny, funcname)) - if shading in ['nearest', 'auto']: + if shading == 'nearest': # grid is specified at the center, so define corners # at the midpoints between the grid centers and then use the # flat algorithm. diff --git a/lib/matplotlib/mpl-data/matplotlibrc b/lib/matplotlib/mpl-data/matplotlibrc index 326d02c2124b..0b8cb1c86f35 100644 --- a/lib/matplotlib/mpl-data/matplotlibrc +++ b/lib/matplotlib/mpl-data/matplotlibrc @@ -130,7 +130,7 @@ #markers.fillstyle: full # {full, left, right, bottom, top, none} -#pcolor.shading: flat +#pcolor.shading: auto #pcolormesh.snap: True # Whether to snap the mesh to pixel boundaries. This is # provided solely to allow old test images to remain # unchanged. Set to False to obtain the previous behavior. diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index feb72f884fc6..3736888fdde5 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -1243,22 +1243,14 @@ def test_pcolornearestunits(fig_test, fig_ref): ax.pcolormesh(x2, y2, Z, shading='nearest') -@check_figures_equal(extensions=["png"]) -def test_pcolordropdata(fig_test, fig_ref): - ax = fig_test.subplots() - x = np.arange(0, 10) - y = np.arange(0, 4) +def test_pcolorflaterror(): + fig, ax = plt.subplots() + x = np.arange(0, 9) + y = np.arange(0, 3) np.random.seed(19680801) Z = np.random.randn(3, 9) - # fake dropping the data - ax.pcolormesh(x[:-1], y[:-1], Z[:-1, :-1], shading='flat') - - ax = fig_ref.subplots() - # test dropping the data... - x2 = x[:-1] - y2 = y[:-1] - with pytest.warns(MatplotlibDeprecationWarning): - ax.pcolormesh(x2, y2, Z, shading='flat') + with pytest.raises(TypeError, match='Dimensions of C'): + ax.pcolormesh(x, y, Z, shading='flat') @check_figures_equal(extensions=["png"]) @@ -1268,13 +1260,15 @@ def test_pcolorauto(fig_test, fig_ref): y = np.arange(0, 4) np.random.seed(19680801) Z = np.random.randn(3, 9) - ax.pcolormesh(x, y, Z, shading='auto') + # this is the same as flat; note that auto is default + ax.pcolormesh(x, y, Z) ax = fig_ref.subplots() # specify the centers x2 = x[:-1] + np.diff(x) / 2 y2 = y[:-1] + np.diff(y) / 2 - ax.pcolormesh(x2, y2, Z, shading='auto') + # this is same as nearest: + ax.pcolormesh(x2, y2, Z) @image_comparison(['canonical'])