From 1fcf591156ce3c9a2b1abbacd5bffd146afdcc6d Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Tue, 21 Jun 2016 10:20:29 -0400 Subject: [PATCH 1/2] colors: ensure masked array data is an ndarray This fixes compatibility for imshow plots with array data that is a unit-aware ndarray subclass, for example data frmo yt.units or astropy.units. --- lib/matplotlib/colors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index 35550f0b743..c35a807ed2a 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -925,7 +925,7 @@ def __call__(self, value, clip=None): result = np.ma.array(np.clip(result.filled(vmax), vmin, vmax), mask=mask) # ma division is very slow; we can take a shortcut - resdat = result.data + resdat = np.asarray(result.data) resdat -= vmin resdat /= (vmax - vmin) result = np.ma.array(resdat, mask=result.mask, copy=False) From 6c9f8a99cb213a17160bff5a6db7997706e16ede Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Tue, 21 Jun 2016 13:51:21 -0400 Subject: [PATCH 2/2] colors: add comment explaining use of np.asarray --- lib/matplotlib/colors.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index c35a807ed2a..511f46d1871 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -925,6 +925,8 @@ def __call__(self, value, clip=None): result = np.ma.array(np.clip(result.filled(vmax), vmin, vmax), mask=mask) # ma division is very slow; we can take a shortcut + # use np.asarray so data passed in as an ndarray subclass are + # interpreted as an ndarray. See issue #6622. resdat = np.asarray(result.data) resdat -= vmin resdat /= (vmax - vmin)