Title: [Bug]: PolyCollection `set_offsets` does not accept `[[], []]` like Line2D · Issue #22401 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: PolyCollection `set_offsets` does not accept `[[], []]` like Line2D · Issue #22401 · matplotlib/matplotlib
X Title: [Bug]: PolyCollection `set_offsets` does not accept `[[], []]` like Line2D · Issue #22401 · matplotlib/matplotlib
Description: Bug summary The return value of plot a Line2D lets you set_data as [[], []] this is nice because you can do both of line = plt.plot([],[])[0] line.set_data([[],[]]) allowing you to make a line disappear by setting it's data to empty. Thi...
Open Graph Description: Bug summary The return value of plot a Line2D lets you set_data as [[], []] this is nice because you can do both of line = plt.plot([],[])[0] line.set_data([[],[]]) allowing you to make a line disa...
X Description: Bug summary The return value of plot a Line2D lets you set_data as [[], []] this is nice because you can do both of line = plt.plot([],[])[0] line.set_data([[],[]]) allowing you to make a line disa...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/22401
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: PolyCollection `set_offsets` does not accept `[[], []]` like Line2D","articleBody":"### Bug summary\r\n\r\nThe return value of `plot` a `Line2D` lets you `set_data` as `[[], []]` this is nice because you can do both of\r\n```python\r\nline = plt.plot([],[])[0]\r\nline.set_data([[],[]])\r\n```\r\nallowing you to make a line disappear by setting it's data to empty. This comes up surprisingly often for me when using mpl-interactions to explore datasets\r\n\r\n\r\nHowever, `plt.scatter` does not have the same symmetry of behavior. You can do \r\n```python\r\nscatter = plt.scatter([[], [])\r\n```\r\n\r\nbut you cannot then do \r\n```python\r\nscatter.set_offsets([[],[]])\r\n```\r\n\r\n### Code for reproduction\r\n\r\n```python\r\n# works\r\nline = plt.plot([],[])[0]\r\n\r\n# works\r\nline.set_data([[],[]])\r\n\r\n# works\r\nscatter = plt.scatter([],[])\r\n\r\n# fails\r\nscatter.set_offsets([[],[]])\r\n```\r\n\r\n\r\n### Actual outcome\r\n```\r\n---------------------------------------------------------------------------\r\nIndexError Traceback (most recent call last)\r\nInput In [76], in \u003cmodule\u003e\r\n 1 scatter = plt.scatter([],[])\r\n----\u003e 2 scatter.set_offsets([[],[]])\r\n\r\nFile ~/mambaforge/envs/mpl-inter/lib/python3.9/site-packages/matplotlib/collections.py:566, in Collection.set_offsets(self, offsets)\r\n 563 if offsets.shape == (2,): # Broadcast (2,) -\u003e (1, 2) but nothing else.\r\n 564 offsets = offsets[None, :]\r\n 565 self._offsets = np.column_stack(\r\n--\u003e 566 (np.asarray(self.convert_xunits(offsets[:, 0]), 'float'),\r\n 567 np.asarray(self.convert_yunits(offsets[:, 1]), 'float')))\r\n 568 self.stale = True\r\n\r\nIndexError: index 0 is out of bounds for axis 1 with size 0\r\n```\r\n### Expected outcome\r\n\r\nNo error and the scatter should not be drawn.\r\n\r\n### Additional information\r\n\r\n_No response_\r\n\r\n### Operating system\r\n\r\n_No response_\r\n\r\n### Matplotlib Version\r\n\r\n3.5.1\r\n\r\n### Matplotlib Backend\r\n\r\nany\r\n\r\n### Python version\r\n\r\n3.9.9\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/ianhi","@type":"Person","name":"ianhi"},"datePublished":"2022-02-05T05:19:45.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/22401/matplotlib/issues/22401"}
| 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:ad7695a5-b437-1e6f-1f33-c38e30014984 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 874E:279B75:B9BA85:FA72B2:6A531C46 |
| html-safe-nonce | 46a80ab6b3c063e1807652cd0b3f22114f4139ae5d2a39c7f2194b99133d4c95 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NzRFOjI3OUI3NTpCOUJBODU6RkE3MkIyOjZBNTMxQzQ2IiwidmlzaXRvcl9pZCI6IjgxNzA3NjMzOTA3NjUxNzc5MjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ba5e5babf2073a45e46970b4b43e7e6b5f98ee598347ba9f786074cfc92c0150 |
| hovercard-subject-tag | issue:1124839120 |
| 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/22401/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c2aa428ce3a6b1fe0942ce041b46823bf5d544b55d035da367a25f5f309e8604/matplotlib/matplotlib/issues/22401 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c2aa428ce3a6b1fe0942ce041b46823bf5d544b55d035da367a25f5f309e8604/matplotlib/matplotlib/issues/22401 |
| og:image:alt | Bug summary The return value of plot a Line2D lets you set_data as [[], []] this is nice because you can do both of line = plt.plot([],[])[0] line.set_data([[],[]]) allowing you to make a line disa... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ianhi |
| 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