Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0e2b9b1

Browse filesBrowse files
authored
Merge pull request #13405 from anntzer/pil_imshow
Fix imshow()ing PIL-opened images.
2 parents ed8e70e + c7cc363 commit 0e2b9b1
Copy full SHA for 0e2b9b1

File tree

Expand file treeCollapse file tree

2 files changed

+11
-10
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+11
-10
lines changed

‎lib/matplotlib/image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/image.py
+1-9Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -649,15 +649,7 @@ def set_data(self, A):
649649
----------
650650
A : array-like
651651
"""
652-
# check if data is PIL Image without importing Image
653-
if hasattr(A, 'getpixel'):
654-
if A.mode == 'L':
655-
# greyscale image, but our logic assumes rgba:
656-
self._A = pil_to_array(A.convert('RGBA'))
657-
else:
658-
self._A = pil_to_array(A)
659-
else:
660-
self._A = cbook.safe_masked_invalid(A, copy=True)
652+
self._A = cbook.safe_masked_invalid(A, copy=True)
661653

662654
if (self._A.dtype != np.uint8 and
663655
not np.can_cast(self._A.dtype, float, "same_kind")):

‎lib/matplotlib/tests/test_image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_image.py
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from matplotlib.cbook import MatplotlibDeprecationWarning
1919
from matplotlib.image import (AxesImage, BboxImage, FigureImage,
2020
NonUniformImage, PcolorImage)
21-
from matplotlib.testing.decorators import image_comparison
21+
from matplotlib.testing.decorators import check_figures_equal, image_comparison
2222
from matplotlib.transforms import Bbox, Affine2D, TransformedBbox
2323

2424
import pytest
@@ -106,6 +106,15 @@ def test_image_python_io():
106106
plt.imread(buffer)
107107

108108

109+
@check_figures_equal()
110+
def test_imshow_pil(fig_test, fig_ref):
111+
pytest.importorskip("PIL")
112+
img = plt.imread(os.path.join(os.path.dirname(__file__),
113+
'baseline_images', 'test_image', 'uint16.tif'))
114+
fig_test.subplots().imshow(img)
115+
fig_ref.subplots().imshow(np.asarray(img))
116+
117+
109118
def test_imread_pil_uint16():
110119
pytest.importorskip("PIL")
111120
img = plt.imread(os.path.join(os.path.dirname(__file__),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.