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

Skip to content

Commit 55ac6dd

Browse files
committed
[ 2173204 ] implot leaves environment unstable after bad image data
Report errors about invalid data sooner when using imshow. svn path=/trunk/matplotlib/; revision=6283
1 parent 1c31886 commit 55ac6dd

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

lib/matplotlib/image.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@ def set_data(self, A, shape=None):
285285
else:
286286
self._A = np.asarray(A) # assume array
287287

288+
if self._A.dtype != np.uint8 and not np.can_cast(self._A.dtype, np.float):
289+
raise TypeError("Image data can not convert to float")
290+
291+
if (self._A.ndim not in (2, 3) or
292+
(self._A.ndim == 3 and self._A.shape[-1] not in (3, 4))):
293+
raise TypeError("Invalid dimensions for image data")
294+
288295
self._imcache =None
289296
self._rgbacache = None
290297
self._oldxslice = None

0 commit comments

Comments
 (0)