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

Skip to content

Commit c1c02f0

Browse files
committed
MNT: effect pcolorarg deprecation and change default shading to auto
TST: udate tests for new pcolormeshdefault DOC
1 parent 6f4eb6d commit c1c02f0

File tree

4 files changed

+25
-29
lines changed

4 files changed

+25
-29
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pcolor(mesh) shading defaults to auto
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
The *shading* kwarg for `.Axes.pcolormesh` and `.Axes.pcolor` default
5+
has been changed to 'auto'.
6+
7+
Passing ``Z(M, N)``, ``x(N)``, ``y(M)`` to ``pcolormesh`` with
8+
``shading='flat'`` will now raise a ``TypeError``. Use
9+
``shading='auto'`` or ``shading='nearest'`` for ``x`` and ``y``
10+
to be treated as cell centers, or drop the last column and row
11+
of ``Z`` to get the old behavior with ``shading='flat'``.

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5603,7 +5603,7 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
56035603
self.add_image(im)
56045604
return im
56055605

5606-
def _pcolorargs(self, funcname, *args, shading='flat', **kwargs):
5606+
def _pcolorargs(self, funcname, *args, shading='auto', **kwargs):
56075607
# - create X and Y if not present;
56085608
# - reshape X and Y as needed if they are 1-D;
56095609
# - check for proper sizes based on `shading` kwarg;
@@ -5675,25 +5675,16 @@ def _pcolorargs(self, funcname, *args, shading='flat', **kwargs):
56755675
shading = 'flat'
56765676

56775677
if shading == 'flat':
5678-
if not (ncols in (Nx, Nx - 1) and nrows in (Ny, Ny - 1)):
5678+
if (Nx, Ny) != (ncols + 1, nrows + 1):
56795679
raise TypeError('Dimensions of C %s are incompatible with'
56805680
' X (%d) and/or Y (%d); see help(%s)' % (
56815681
C.shape, Nx, Ny, funcname))
5682-
if (ncols == Nx or nrows == Ny):
5683-
_api.warn_deprecated(
5684-
"3.3", message="shading='flat' when X and Y have the same "
5685-
"dimensions as C is deprecated since %(since)s. Either "
5686-
"specify the corners of the quadrilaterals with X and Y, "
5687-
"or pass shading='auto', 'nearest' or 'gouraud', or set "
5688-
"rcParams['pcolor.shading']. This will become an error "
5689-
"%(removal)s.")
5690-
C = C[:Ny - 1, :Nx - 1]
56915682
else: # ['nearest', 'gouraud']:
56925683
if (Nx, Ny) != (ncols, nrows):
56935684
raise TypeError('Dimensions of C %s are incompatible with'
56945685
' X (%d) and/or Y (%d); see help(%s)' % (
56955686
C.shape, Nx, Ny, funcname))
5696-
if shading in ['nearest', 'auto']:
5687+
if shading == 'nearest':
56975688
# grid is specified at the center, so define corners
56985689
# at the midpoints between the grid centers and then use the
56995690
# flat algorithm.

lib/matplotlib/mpl-data/matplotlibrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130

131131
#markers.fillstyle: full # {full, left, right, bottom, top, none}
132132

133-
#pcolor.shading: flat
133+
#pcolor.shading: auto
134134
#pcolormesh.snap: True # Whether to snap the mesh to pixel boundaries. This is
135135
# provided solely to allow old test images to remain
136136
# unchanged. Set to False to obtain the previous behavior.

lib/matplotlib/tests/test_axes.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,22 +1243,14 @@ def test_pcolornearestunits(fig_test, fig_ref):
12431243
ax.pcolormesh(x2, y2, Z, shading='nearest')
12441244

12451245

1246-
@check_figures_equal(extensions=["png"])
1247-
def test_pcolordropdata(fig_test, fig_ref):
1248-
ax = fig_test.subplots()
1249-
x = np.arange(0, 10)
1250-
y = np.arange(0, 4)
1246+
def test_pcolorflaterror():
1247+
fig, ax = plt.subplots()
1248+
x = np.arange(0, 9)
1249+
y = np.arange(0, 3)
12511250
np.random.seed(19680801)
12521251
Z = np.random.randn(3, 9)
1253-
# fake dropping the data
1254-
ax.pcolormesh(x[:-1], y[:-1], Z[:-1, :-1], shading='flat')
1255-
1256-
ax = fig_ref.subplots()
1257-
# test dropping the data...
1258-
x2 = x[:-1]
1259-
y2 = y[:-1]
1260-
with pytest.warns(MatplotlibDeprecationWarning):
1261-
ax.pcolormesh(x2, y2, Z, shading='flat')
1252+
with pytest.raises(TypeError, match='Dimensions of C'):
1253+
ax.pcolormesh(x, y, Z, shading='flat')
12621254

12631255

12641256
@check_figures_equal(extensions=["png"])
@@ -1268,13 +1260,15 @@ def test_pcolorauto(fig_test, fig_ref):
12681260
y = np.arange(0, 4)
12691261
np.random.seed(19680801)
12701262
Z = np.random.randn(3, 9)
1271-
ax.pcolormesh(x, y, Z, shading='auto')
1263+
# this is the same as flat; note that auto is default
1264+
ax.pcolormesh(x, y, Z)
12721265

12731266
ax = fig_ref.subplots()
12741267
# specify the centers
12751268
x2 = x[:-1] + np.diff(x) / 2
12761269
y2 = y[:-1] + np.diff(y) / 2
1277-
ax.pcolormesh(x2, y2, Z, shading='auto')
1270+
# this is same as nearest:
1271+
ax.pcolormesh(x2, y2, Z)
12781272

12791273

12801274
@image_comparison(['canonical'])

0 commit comments

Comments
 (0)