[Bug]: Doesn't show 1-channel image by using matplotlib.image.AxesImage.set_data() · Issue #22808 · matplotlib/matplotlib · GitHub
Skip to content

[Bug]: Doesn't show 1-channel image by using matplotlib.image.AxesImage.set_data() #22808

Description

@nicolasrosa

Bug summary

I could not plot a 1-channel image while I was trying to populate a Subplots figure, although I can visualize it by using plt.imshow().

Code for reproduction

fig, axes = plt.subplots(3, 2, num=0)
# fig.canvas.mpl_connect('key_press_event', on_press)

h, w = image_size
h, w = int(h), int(w)

ax1 = axes[0][0].imshow(np.zeros((h, w, 3), dtype=np.float32))
ax2 = axes[0][1].imshow(np.zeros((h, w, 3), dtype=np.float32))
ax3 = axes[1][0].imshow(np.zeros((h, w, 3), dtype=np.float32))
ax4 = axes[1][1].imshow(np.zeros((h, w, 3), dtype=np.float32))
ax5 = axes[2][0].imshow(np.zeros((h, w), dtype=np.float32)) 
ax6 = axes[2][1].imshow(np.zeros((h, w), dtype=np.float32))

image_np = <(h,w) uint8 or float32>
image_pil = Image.fromarray(image_np).convert('RGB')

...
# ax5.set_data(image_np)  # Fails!
# ax5.set_data(image_pil)  # Works!
plt.imshow(image_np)  # Works!
plt.draw()
plt.pause(1e-9)

Actual outcome

matplotlib_bug

Expected outcome

I used the Paint to generate the following image to demonstrate what I was expecting.

matplotlib_fix_paint

Additional information

No response

Operating system

Ubuntu 20.04

Matplotlib Version

3.5.1

Matplotlib Backend

TkAgg

Python version

Python 3.8.10

Jupyter version

No response

Installation

pip

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.status: inactiveMarked by the “Stale” Github Actiontopic: images

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions