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

Skip to content

Commit 2204dd1

Browse files
committed
removed shading=auto and changed tests
1 parent 8d24d02 commit 2204dd1

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

lib/matplotlib/cm.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,11 @@ def to_rgba(self, x, alpha=None, bytes=False, norm=True):
361361

362362
def set_array(self, A):
363363
"""
364-
Set the image array from numpy array *A*.
364+
Set the image array from array-like *A*.
365365
366366
Parameters
367367
----------
368-
A : ndarray or None
368+
A : array-like or None
369369
"""
370370
if A is None:
371371
self._A = None
@@ -375,14 +375,14 @@ def set_array(self, A):
375375
A_ = A.ravel()
376376
width, height = self._meshWidth, self._meshHeight
377377
if self._shading == 'flat':
378-
if not ( len(A_) == width * height or
379-
len(A_) == (width + 1) * (height + 1)):
378+
if not (len(A_) == width * height or
379+
len(A_) == (width + 1) * (height + 1)):
380380
raise TypeError(
381381
'Dimensions of A %s are incompatible with '
382382
'X (%d) and/or Y (%d)' %
383383
(A.shape, width, height))
384384
elif self._shading == 'nearest':
385-
if not ( len(A_) == width * height:
385+
if not (len(A_) == width * height):
386386
raise TypeError(
387387
'Dimensions of A %s are incompatible with '
388388
'X (%d) and/or Y (%d)' %
@@ -394,6 +394,11 @@ def set_array(self, A):
394394
'X (%d) and/or Y (%d)' %
395395
(A.shape, width, height))
396396

397+
A = cbook.safe_masked_invalid(A, copy=True)
398+
if not np.can_cast(A.dtype, float, "same_kind"):
399+
raise TypeError(f"Image data of dtype {A.dtype} cannot be "
400+
"converted to float")
401+
397402
self._A = A
398403

399404
def get_array(self):

lib/matplotlib/tests/test_collections.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -705,15 +705,16 @@ def test_quadmesh_set_array_validation():
705705
z = np.arange(9).reshape((3, 3))
706706
fig, ax = plt.subplots()
707707
coll = ax.pcolormesh(x, y, np.ones(z.shape))
708-
z = np.arange(16).reshape((4, 4))
708+
z = np.arange(25).reshape((5, 5))
709709

710-
with pytest.raises(TypeError, match=re.escape("Dimensions of A (4, 4) "
710+
with pytest.raises(TypeError, match=re.escape("Dimensions of A (5, 5) "
711711
"are incompatible with X (3) and/or Y (3)")):
712712
coll.set_array(z)
713-
with pytest.raises(TypeError, match=re.escape("Dimensions of A (16,) "
713+
with pytest.raises(TypeError, match=re.escape("Dimensions of A (25,) "
714714
"are incompatible with X (3) and/or Y (3)")):
715715
coll.set_array(z.ravel())
716716

717+
z = np.arange(16).reshape((4, 4))
717718
fig, ax = plt.subplots()
718719
coll = ax.pcolormesh(x, y, np.ones(z.shape), shading='nearest')
719720
with pytest.raises(TypeError, match=re.escape("Dimensions of A (3, 3) "

0 commit comments

Comments
 (0)