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

Skip to content

Commit aa28223

Browse files
anntzermeeseeksmachine
authored andcommitted
Backport PR #21293: Fix snap argument to pcolormesh
1 parent 12ceb30 commit aa28223

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6016,9 +6016,10 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
60166016
# convert to one dimensional array
60176017
C = C.ravel()
60186018

6019-
snap = kwargs.get('snap', rcParams['pcolormesh.snap'])
6019+
kwargs.setdefault('snap', rcParams['pcolormesh.snap'])
6020+
60206021
collection = mcoll.QuadMesh(
6021-
coords, antialiased=antialiased, shading=shading, snap=snap,
6022+
coords, antialiased=antialiased, shading=shading,
60226023
array=C, cmap=cmap, norm=norm, alpha=alpha, **kwargs)
60236024
collection._scale_norm(norm, vmin, vmax)
60246025
self._pcolor_grid_deprecation_helper()

lib/matplotlib/tests/test_axes.py

Lines changed: 4 additions & 3 deletions
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)