Title: `_axes.py.scatter()` array index out of bound / calling from `seaborn` · Issue #12641 · matplotlib/matplotlib · GitHub
Open Graph Title: `_axes.py.scatter()` array index out of bound / calling from `seaborn` · Issue #12641 · matplotlib/matplotlib
X Title: `_axes.py.scatter()` array index out of bound / calling from `seaborn` · Issue #12641 · matplotlib/matplotlib
Description: Bug report Bug summary Seeing this with matplotlib 3.0.1 and seaborn 0.9. cc @mwaskom matplotlib.axes._axes.scatter() tests parameter c hits array index out of bound when c is an empty array. I encountered this while using seaborn.swarmp...
Open Graph Description: Bug report Bug summary Seeing this with matplotlib 3.0.1 and seaborn 0.9. cc @mwaskom matplotlib.axes._axes.scatter() tests parameter c hits array index out of bound when c is an empty array. I enc...
X Description: Bug report Bug summary Seeing this with matplotlib 3.0.1 and seaborn 0.9. cc @mwaskom matplotlib.axes._axes.scatter() tests parameter c hits array index out of bound when c is an empty array. I enc...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/12641
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`_axes.py.scatter()` array index out of bound / calling from `seaborn`","articleBody":"### Bug report\r\n\r\n**Bug summary**\r\n\r\nSeeing this with `matplotlib 3.0.1` and `seaborn 0.9`. cc @mwaskom\r\n \r\n[matplotlib.axes._axes.scatter()](https://github.com/matplotlib/matplotlib/blob/921d4f4ab7ae2eb0feda02a364e8d63c6b6709c5/lib/matplotlib/axes/_axes.py#L4192) tests parameter `c` hits `array index out of bound` when `c` is an empty array. \r\n\r\nI encountered this while using `seaborn.swarmplot()` with `hue=` parameter. Essentially this plots each group (`hue`, in addition to x-axis category) and some times a group can be empty for a major x-axis category. \r\n\r\nSuggest potential fix to test length of `c` as well before accessing `c[0]`. \r\n\r\n```\r\n if (c_none or\r\n co is not None or\r\n isinstance(c, str) or\r\n (isinstance(c, collections.Iterable) and \r\n len(c) \u003e 0 and # proposed fix here\r\n isinstance(c[0], str))):\r\n```\r\n\r\n**Code for reproduction**\r\n\r\n\u003c!--A minimum code snippet required to reproduce the bug, also minimizing the number of dependencies required--\u003e\r\n\r\n```python\r\nimport pandas as pd\r\nimport seaborn as sns\r\n\r\ndf = pd.DataFrame(dict(category=['a', 'a', 'b', 'b', 'c'],\r\n hue=['x', 'y', 'x', 'y', 'x'],\r\n values=[1, 2, 3, 4, 3]))\r\nsns.swarmplot('category', 'values', hue='hue', data=df, dodge=True)\r\n```\r\n\r\n**Actual outcome**\r\n\r\nThis is the error I see:\r\n\r\n```\r\nIndexError Traceback (most recent call last)\r\n\u003cipython-input-5-0368a082f6a8\u003e in \u003cmodule\u003e\r\n----\u003e 1 sns.swarmplot('category', 'values', hue='hue', data=df, dodge=True)\r\n\r\nh:\\anaconda3\\lib\\site-packages\\seaborn\\categorical.py in swarmplot(x, y, hue, data, order, hue_order, dodge, orient, color, palette, size, edgecolor, linewidth, ax, **kwargs)\r\n 2989 linewidth=linewidth))\r\n 2990 \r\n-\u003e 2991 plotter.plot(ax, kwargs)\r\n 2992 return ax\r\n 2993 \r\n\r\nh:\\anaconda3\\lib\\site-packages\\seaborn\\categorical.py in plot(self, ax, kws)\r\n 1444 def plot(self, ax, kws):\r\n 1445 \"\"\"Make the full plot.\"\"\"\r\n-\u003e 1446 self.draw_swarmplot(ax, kws)\r\n 1447 self.add_legend_data(ax)\r\n 1448 self.annotate_axes(ax)\r\n\r\nh:\\anaconda3\\lib\\site-packages\\seaborn\\categorical.py in draw_swarmplot(self, ax, kws)\r\n 1429 kws.update(c=point_colors)\r\n 1430 if self.orient == \"v\":\r\n-\u003e 1431 points = ax.scatter(cat_pos, swarm_data, s=s, **kws)\r\n 1432 else:\r\n 1433 points = ax.scatter(swarm_data, cat_pos, s=s, **kws)\r\n\r\nh:\\anaconda3\\lib\\site-packages\\matplotlib\\__init__.py in inner(ax, data, *args, **kwargs)\r\n 1803 \"the Matplotlib list!)\" % (label_namer, func.__name__),\r\n 1804 RuntimeWarning, stacklevel=2)\r\n-\u003e 1805 return func(ax, *args, **kwargs)\r\n 1806 \r\n 1807 inner.__doc__ = _add_data_doc(inner.__doc__,\r\n\r\nh:\\anaconda3\\lib\\site-packages\\matplotlib\\axes\\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)\r\n 4194 (isinstance(c, collections.Iterable) and\r\n 4195 # len(c) \u003e 0 and\r\n-\u003e 4196 isinstance(c[0], str))):\r\n 4197 c_array = None\r\n 4198 else:\r\n\r\nIndexError: index 0 is out of bounds for axis 0 with size 0\r\n```\r\n\r\nHappy to create a PR if we have happy with the proposed length test.\r\n","author":{"url":"https://github.com/esvhd","@type":"Person","name":"esvhd"},"datePublished":"2018-10-26T12:44:49.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":28},"url":"https://github.com/12641/matplotlib/issues/12641"}
| 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:d29bf6b9-be2f-aa3d-700c-5dd52caf8e73 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DCEA:2BB05E:3F2E71:5A86E9:6A5485DD |
| html-safe-nonce | b32a831e2a729851a4b72b3a8cc514db3b4d647f59fd14a06383199767cbb6f0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQ0VBOjJCQjA1RTozRjJFNzE6NUE4NkU5OjZBNTQ4NUREIiwidmlzaXRvcl9pZCI6IjE0ODUxODE5Mjg3NTU5ODc5MzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1332ff2c14ba737b1a6333ae05419df7689bc83738bdf5ac0e0289cf026dc704 |
| hovercard-subject-tag | issue:374367401 |
| 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/12641/issue_layout |
| twitter:image | https://opengraph.githubassets.com/da419dfe52a58475bd1cadb2d00295060c4f0f14d9cda0edcdb3db2a12ab2eec/matplotlib/matplotlib/issues/12641 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/da419dfe52a58475bd1cadb2d00295060c4f0f14d9cda0edcdb3db2a12ab2eec/matplotlib/matplotlib/issues/12641 |
| og:image:alt | Bug report Bug summary Seeing this with matplotlib 3.0.1 and seaborn 0.9. cc @mwaskom matplotlib.axes._axes.scatter() tests parameter c hits array index out of bound when c is an empty array. I enc... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | esvhd |
| 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 | 03ccb116376fd46e8ba2a4cdc541e35f13f70734 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width