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

Skip to content

Commit f443b12

Browse files
authored
Merge pull request #6674 from tacaswell/fix_imshow_endiannes
FIX: handle non-native endian images
2 parents 8916067 + e077c13 commit f443b12

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

lib/matplotlib/cbook.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,13 @@ def issubclass_safe(x, klass):
15051505

15061506
def safe_masked_invalid(x, copy=False):
15071507
x = np.array(x, subok=True, copy=copy)
1508+
if not x.dtype.isnative:
1509+
# Note that the argument to `byteswap` is 'inplace',
1510+
# thus if we have already made a copy, do the byteswap in
1511+
# place, else make a copy with the byte order swapped.
1512+
# Be explicit that we are swapping the byte order of the dtype
1513+
x = x.byteswap(copy).newbyteorder('S')
1514+
15081515
try:
15091516
xm = np.ma.masked_invalid(x, copy=False)
15101517
xm.shrink_mask()

lib/matplotlib/tests/test_image.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,21 @@ def test_mask_image():
715715
ax2.imshow(A, interpolation='nearest')
716716

717717

718-
if __name__=='__main__':
719-
import nose
720-
nose.runmodule(argv=['-s','--with-doctest'], exit=False)
718+
@image_comparison(baseline_images=['imshow_endianess'],
719+
remove_text=True, extensions=['png'])
720+
def test_imshow_endianess():
721+
x = np.arange(10)
722+
X, Y = np.meshgrid(x, x)
723+
Z = ((X-5)**2 + (Y-5)**2)**0.5
724+
725+
fig, (ax1, ax2) = plt.subplots(1, 2)
726+
727+
kwargs = dict(origin="lower", interpolation='nearest',
728+
cmap='viridis')
729+
730+
ax1.imshow(Z.astype('<f8'), **kwargs)
731+
ax2.imshow(Z.astype('>f8'), **kwargs)
732+
733+
734+
if __name__ == '__main__':
735+
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
 (0)