8000 Merge pull request #13416 from meeseeksmachine/auto-backport-of-pr-13… · matplotlib/matplotlib@c3653e4 · GitHub
[go: up one dir, main page]

Skip to content

Commit c3653e4

Browse files
authored
Merge pull request #13416 from meeseeksmachine/auto-backport-of-pr-13405-on-v3.0.x
Backport PR #13405 on branch v3.0.x (Fix imshow()ing PIL-opened images.)
2 parents 69c2a9d + f8f3145 commit c3653e4

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

lib/matplotlib/image.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -627,15 +627,7 @@ def set_data(self, A):
627627
----------
628628
A : array-like
629629
"""
630-
# check if data is PIL Image without importing Image
631-
if hasattr(A, 'getpixel'):
632-
if A.mode == 'L':
633-
# greyscale image, but our logic assumes rgba:
634-
self._A = pil_to_array(A.convert('RGBA'))
635-
else:
636-
self._A = pil_to_array(A)
637-
else:
638-
self._A = cbook.safe_masked_invalid(A, copy=True)
630+
self._A = cbook.safe_masked_invalid(A, copy=True)
639631

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

lib/matplotlib/tests/test_image.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
rc_context, rcParams)
1717
from matplotlib.image import (AxesImage, BboxImage, FigureImage,
1818
NonUniformImage, PcolorImage)
19-
from matplotlib.testing.decorators import image_comparison
19+
from matplotlib.testing.decorators import check_figures_equal, image_comparison
2020
from matplotlib.transforms import Bbox, Affine2D, TransformedBbox
2121

2222
import pytest
@@ -104,6 +104,15 @@ def test_image_python_io():
104104
plt.imread(buffer)
105105

106106

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

0 commit comments

Comments
 (0)
0