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

Skip to content

Commit ebe1fb2

Browse files
committed
Correctly apply PNG palette when building ImageBase through Pillow.
1 parent e551980 commit ebe1fb2

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/matplotlib/image.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,13 @@ def set_data(self, A):
667667
----------
668668
A : array-like
669669
"""
670+
try:
671+
from PIL import Image
672+
except ImportError:
673+
pass
674+
else:
675+
if isinstance(A, Image.Image):
676+
A = pil_to_array(A) # Needed e.g. to apply png palette.
670677
self._A = cbook.safe_masked_invalid(A, copy=True)
671678

672679
if (self._A.dtype != np.uint8 and

0 commit comments

Comments
 (0)