Skip to content

plt.imshow() error on PIL-opened tiff images #12140

Closed
@anntzer

Description

@anntzer
plt.imshow(PIL.Image.open("lib/matplotlib/tests/baseline_images/test_image/uint16.tif"))

fails with

<elided>
  File "/home/antony/src/extern/matplotlib/lib/matplotlib/image.py", line 838, in make_image
    unsampled=unsampled)
  File "/home/antony/src/extern/matplotlib/lib/matplotlib/image.py", line 447, in _make_image
    if A.mask.shape == A.shape:
AttributeError: 'numpy.ndarray' object has no attribute 'mask'

since 12c27f3 (mpl 2.1 @tacaswell); previously it was possible to directly plot PIL-opened images (which do follow the standard buffer protocol).

It is not particularly problematic because one can just wrap explicitly the PIL-opened image using np.asarray, or use plt.imread instead (which does exactly that); still, I'm raising the issue here in case we want to fix it. (Or documenting that we no longer support PIL images is fine too, again the workaround is not that bad.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions