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

Skip to content

Commit 71dc77d

Browse files
committed
Expand set_array for array-like input
1 parent c22b2eb commit 71dc77d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/matplotlib/cm.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,19 @@ 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
"""
370+
A = cbook.safe_masked_invalid(A, copy=True) if A is not None else None
371+
372+
if (A is not None and A.dtype != np.uint8 and
373+
not np.can_cast(A.dtype, float, "same_kind")):
374+
raise TypeError("Image data of dtype {} cannot be converted to "
375+
"float".format(A.dtype))
376+
370377
self._A = A
371378

372379
def get_array(self):

0 commit comments

Comments
 (0)