Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Api pcolorargs deprecation #20268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2021
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
11 changes: 11 additions & 0 deletions doc/api/next_api_changes/behavior/20268-JMK.rst
Original file line number Diff line number Diff line change
@@ -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'``.
15 changes: 3 additions & 12 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/mpl-data/matplotlibrc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 10 additions & 16 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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'])
Expand Down