Skip to content

Commit 8837c9f

Browse files
committed
Fix snap argument to pcolormesh
If it's passed as a keyword argument, then it needs to be removed from `kwargs`, or not passed again explicitly. Other handling of `snap` uses `setdefault`, so do that here too.
1 parent 253cfe8 commit 8837c9f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/matplotlib/axes/_axes.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -6029,9 +6029,10 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
60296029
# convert to one dimensional array
60306030
C = C.ravel()
60316031

6032-
snap = kwargs.get('snap', rcParams['pcolormesh.snap'])
6032+
kwargs.setdefault('snap', rcParams['pcolormesh.snap'])
6033+
60336034
collection = mcoll.QuadMesh(
6034-
coords, antialiased=antialiased, shading=shading, snap=snap,
6035+
coords, antialiased=antialiased, shading=shading,
60356036
array=C, cmap=cmap, norm=norm, alpha=alpha, **kwargs)
60366037
collection._scale_norm(norm, vmin, vmax)
60376038
self._pcolor_grid_deprecation_helper()

lib/matplotlib/tests/test_axes.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1249,22 +1249,23 @@ def test_pcolorflaterror():
12491249
ax.pcolormesh(x, y, Z, shading='flat')
12501250

12511251

1252+
@pytest.mark.parametrize('snap', [False, True])
12521253
@check_figures_equal(extensions=["png"])
1253-
def test_pcolorauto(fig_test, fig_ref):
1254+
def test_pcolorauto(fig_test, fig_ref, snap):
12541255
ax = fig_test.subplots()
12551256
x = np.arange(0, 10)
12561257
y = np.arange(0, 4)
12571258
np.random.seed(19680801)
12581259
Z = np.random.randn(3, 9)
12591260
# this is the same as flat; note that auto is default
1260-
ax.pcolormesh(x, y, Z)
1261+
ax.pcolormesh(x, y, Z, snap=snap)
12611262

12621263
ax = fig_ref.subplots()
12631264
# specify the centers
12641265
x2 = x[:-1] + np.diff(x) / 2
12651266
y2 = y[:-1] + np.diff(y) / 2
12661267
# this is same as nearest:
1267-
ax.pcolormesh(x2, y2, Z)
1268+
ax.pcolormesh(x2, y2, Z, snap=snap)
12681269

12691270

12701271
@image_comparison(['canonical'])

0 commit comments

Comments
 (0)