diff --git a/lib/matplotlib/cbook.py b/lib/matplotlib/cbook.py index 8fef27ac0165..ab0cc8edec27 100644 --- a/lib/matplotlib/cbook.py +++ b/lib/matplotlib/cbook.py @@ -1505,6 +1505,13 @@ def issubclass_safe(x, klass): def safe_masked_invalid(x, copy=False): x = np.array(x, subok=True, copy=copy) + if not x.dtype.isnative: + # Note that the argument to `byteswap` is 'inplace', + # thus if we have already made a copy, do the byteswap in + # place, else make a copy with the byte order swapped. + # Be explicit that we are swapping the byte order of the dtype + x = x.byteswap(copy).newbyteorder('S') + try: xm = np.ma.masked_invalid(x, copy=False) xm.shrink_mask() diff --git a/lib/matplotlib/tests/baseline_images/test_image/imshow_endianess.png b/lib/matplotlib/tests/baseline_images/test_image/imshow_endianess.png new file mode 100644 index 000000000000..148acf125174 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_image/imshow_endianess.png differ diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 23d842f79aee..29cc7a98e638 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -677,6 +677,21 @@ def test_mask_image(): ax2.imshow(A, interpolation='nearest') -if __name__=='__main__': - import nose - nose.runmodule(argv=['-s','--with-doctest'], exit=False) +@image_comparison(baseline_images=['imshow_endianess'], + remove_text=True, extensions=['png']) +def test_imshow_endianess(): + x = np.arange(10) + X, Y = np.meshgrid(x, x) + Z = ((X-5)**2 + (Y-5)**2)**0.5 + + fig, (ax1, ax2) = plt.subplots(1, 2) + + kwargs = dict(origin="lower", interpolation='nearest', + cmap='viridis') + + ax1.imshow(Z.astype('f8'), **kwargs) + + +if __name__ == '__main__': + nose.runmodule(argv=['-s', '--with-doctest'], exit=False)