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 c3653e4

Browse filesBrowse 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
Copy full SHA for c3653e4

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
@@ -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

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
@@ -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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.