Skip to content

Commit 9d5e9ee

Browse files
committed
Add comment and test for _pcolorargs
1 parent 86e5eef commit 9d5e9ee

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

lib/matplotlib/axes.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7316,13 +7316,33 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
73167316

73177317
return im
73187318

7319-
def _pcolorargs(self, funcname, *args, **kw):
7319+
@staticmethod
7320+
def _pcolorargs(funcname, *args, **kw):
7321+
# This takes one kwarg, allmatch.
7322+
# If allmatch is True, then the incoming X, Y, C must
7323+
# have matching dimensions, taking into account that
7324+
# X and Y can be 1-D rather than 2-D. This perfect
7325+
# match is required for Gouroud shading. For flat
7326+
# shading, X and Y specify boundaries, so we need
7327+
# one more boundary than color in each direction.
7328+
# For convenience, and consistent with Matlab, we
7329+
# discard the last row and/or column of C if necessary
7330+
# to meet this condition. This is done if allmatch
7331+
# is False.
7332+
73207333
allmatch = kw.pop("allmatch", False)
7334+
73217335
if len(args) == 1:
73227336
C = args[0]
73237337
numRows, numCols = C.shape
7324-
X, Y = np.meshgrid(np.arange(numCols + 1), np.arange(numRows + 1))
7325-
elif len(args) == 3:
7338+
if allmatch:
7339+
X, Y = np.meshgrid(np.arange(numCols), np.arange(numRows))
7340+
else:
7341+
X, Y = np.meshgrid(np.arange(numCols + 1),
7342+
np.arange(numRows + 1))
7343+
return X, Y, C
7344+
7345+
if len(args) == 3:
73267346
X, Y, C = args
73277347
numRows, numCols = C.shape
73287348
else:

lib/matplotlib/tests/test_axes.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from nose.tools import assert_equal
2+
from nose.tools import assert_raises
3+
24
import numpy as np
35
from numpy import ma
46

@@ -293,7 +295,6 @@ def test_shaped_data():
293295
plt.plot( y2 )
294296

295297
plt.subplot( 413 )
296-
from nose.tools import assert_raises
297298
assert_raises(ValueError,plt.plot, (y1,y2))
298299

299300
plt.subplot( 414 )
@@ -662,6 +663,20 @@ def test_pcolormesh():
662663
ax = fig.add_subplot(133)
663664
ax.pcolormesh(Qx,Qz,Z, shading="gouraud")
664665

666+
def test_pcolorargs():
667+
n = 12
668+
x = np.linspace(-1.5, 1.5, n)
669+
y = np.linspace(-1.5, 1.5, n*2)
670+
X, Y = np.meshgrid(x, y)
671+
Z = np.sqrt(X**2 + Y**2)/5
672+
673+
_, ax = plt.subplots()
674+
assert_raises(TypeError, ax.pcolormesh, y, x, Z)
675+
assert_raises(TypeError, ax.pcolormesh, X, Y, Z.T)
676+
assert_raises(TypeError, ax.pcolormesh, x, y, Z[:-1, :-1],
677+
shading="gouraud")
678+
assert_raises(TypeError, ax.pcolormesh, X, Y, Z[:-1, :-1],
679+
shading="gouraud")
665680

666681
@image_comparison(baseline_images=['canonical'])
667682
def test_canonical():

0 commit comments

Comments
 (0)