Skip to content

FIX: handle non-native endian images #6674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
FIX: handle non-native endian images
In cbook.safe_mask_invalid also ensure that the data is in
native byte order.

close #6671 closes #6394
  • Loading branch information
tacaswell committed Jul 6, 2016
commit e077c13bafd0d139dd2816acdad86b10c38b7a48
7 changes: 7 additions & 0 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 18 additions & 3 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
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)