Skip to content

Commit

Permalink
FIX: handle non-native endian images
Browse files Browse the repository at this point in the history
In cbook.safe_mask_invalid also ensure that the data is in
native byte order.

close matplotlib#6671 closes matplotlib#6394
  • Loading branch information
tacaswell committed Jul 2, 2016
1 parent c4fa469 commit 6f4dbf8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
8 changes: 8 additions & 0 deletions lib/matplotlib/cbook.py
Expand Up @@ -1505,6 +1505,14 @@ 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:
if copy:
# if a copy, swap in place
x.byteswap(True)
x = x.newbyteorder()
else:
# otherwise make a swapped copy
x = x.byteswap(False).newbyteorder()
try:
xm = np.ma.masked_invalid(x, copy=False)
xm.shrink_mask()
Expand Down
21 changes: 18 additions & 3 deletions lib/matplotlib/tests/test_image.py
Expand Up @@ -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),
ax2.imshow(Z.astype('>f8'), **kwargs),


if __name__ == '__main__':
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 comments on commit 6f4dbf8

Please sign in to comment.