Title: [Bug]: Doesn't show 1-channel image by using matplotlib.image.AxesImage.set_data() · Issue #22808 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Doesn't show 1-channel image by using matplotlib.image.AxesImage.set_data() · Issue #22808 · matplotlib/matplotlib
X Title: [Bug]: Doesn't show 1-channel image by using matplotlib.image.AxesImage.set_data() · Issue #22808 · matplotlib/matplotlib
Description: 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...
Open Graph Description: 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,...
X Description: 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,...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/22808
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Doesn't show 1-channel image by using matplotlib.image.AxesImage.set_data()","articleBody":"### Bug summary\r\n\r\nI 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().\r\n\r\n### Code for reproduction\r\n\r\n```python\r\nfig, axes = plt.subplots(3, 2, num=0)\r\n# fig.canvas.mpl_connect('key_press_event', on_press)\r\n\r\nh, w = image_size\r\nh, w = int(h), int(w)\r\n\r\nax1 = axes[0][0].imshow(np.zeros((h, w, 3), dtype=np.float32))\r\nax2 = axes[0][1].imshow(np.zeros((h, w, 3), dtype=np.float32))\r\nax3 = axes[1][0].imshow(np.zeros((h, w, 3), dtype=np.float32))\r\nax4 = axes[1][1].imshow(np.zeros((h, w, 3), dtype=np.float32))\r\nax5 = axes[2][0].imshow(np.zeros((h, w), dtype=np.float32)) \r\nax6 = axes[2][1].imshow(np.zeros((h, w), dtype=np.float32))\r\n\r\nimage_np = \u003c(h,w) uint8 or float32\u003e\r\nimage_pil = Image.fromarray(image_np).convert('RGB')\r\n\r\n...\r\n# ax5.set_data(image_np) # Fails!\r\n# ax5.set_data(image_pil) # Works!\r\nplt.imshow(image_np) # Works!\r\nplt.draw()\r\nplt.pause(1e-9)\r\n```\r\n\r\n\r\n### Actual outcome\r\n\r\n\r\n\r\n\r\n### Expected outcome\r\n\r\nI used the Paint to generate the following image to demonstrate what I was expecting.\r\n\r\n\r\n\r\n\r\n### Additional information\r\n\r\n_No response_\r\n\r\n### Operating system\r\n\r\nUbuntu 20.04\r\n\r\n### Matplotlib Version\r\n\r\n3.5.1\r\n\r\n### Matplotlib Backend\r\n\r\nTkAgg\r\n\r\n### Python version\r\n\r\nPython 3.8.10\r\n\r\n### Jupyter version\r\n\r\n_No response_\r\n\r\n### Installation\r\n\r\npip","author":{"url":"https://github.com/nicolasrosa","@type":"Person","name":"nicolasrosa"},"datePublished":"2022-04-08T21:23:39.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":13},"url":"https://github.com/22808/matplotlib/issues/22808"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e7f516c8-9e94-41cc-2eb1-4f974c1a29a6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 985E:382280:5BEA32:79C0FB:6A53EE6C |
| html-safe-nonce | 7f69e5f566ec7781da0f32cd76f2825fa001c352c9d93f3a0c2762624c52045c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5ODVFOjM4MjI4MDo1QkVBMzI6NzlDMEZCOjZBNTNFRTZDIiwidmlzaXRvcl9pZCI6IjY1NzAxNzEwMzY4MDUwOTkxMTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a825cf6602ae45022d7d1e1a44afd95323bd45380fed800fe56d7087a279d309 |
| hovercard-subject-tag | issue:1197848211 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/22808/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f108889fd2bebf8203ae3a01ca20b2f970932d4575c11f1537902ddb4ae8720b/matplotlib/matplotlib/issues/22808 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f108889fd2bebf8203ae3a01ca20b2f970932d4575c11f1537902ddb4ae8720b/matplotlib/matplotlib/issues/22808 |
| og:image:alt | 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,... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nicolasrosa |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width