Title: [Bug]: array-like linewidth raises an error for scatter3D · Issue #23433 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: array-like linewidth raises an error for scatter3D · Issue #23433 · matplotlib/matplotlib
X Title: [Bug]: array-like linewidth raises an error for scatter3D · Issue #23433 · matplotlib/matplotlib
Description: Bug summary The documentation says that linewidths can be float or array-like and it defaults to 1.5, but passing an array-like leads to an error Code for reproduction import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subpl...
Open Graph Description: Bug summary The documentation says that linewidths can be float or array-like and it defaults to 1.5, but passing an array-like leads to an error Code for reproduction import matplotlib.pyplot as p...
X Description: Bug summary The documentation says that linewidths can be float or array-like and it defaults to 1.5, but passing an array-like leads to an error Code for reproduction import matplotlib.pyplot as p...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/23433
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: array-like linewidth raises an error for scatter3D","articleBody":"### Bug summary\r\n\r\nThe documentation says that `linewidths` can be `float or array-like` and it defaults to 1.5, but passing an array-like leads to an error\r\n\r\n### Code for reproduction\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\n\r\nfig = plt.figure()\r\nax = fig.add_subplot(projection='3d')\r\nx = range(1, 10)\r\nax.scatter(x, x, x, marker='o', s=x, linewidth=x)\r\nplt.show()\r\n```\r\n\r\n\r\n### Actual outcome\r\n\r\nException:\r\n\r\n```\r\nmpl_toolkits/mplot3d/axes3d.py in do_3d_projection(artist)\r\n 469 # avoid passing it to them; call this directly once the\r\n 470 # deprecation has expired.\r\n--\u003e 471 return artist.do_3d_projection()\r\n 472 \r\n 473 _api.warn_deprecated(\r\n\r\nmatplotlib/_api/deprecation.py in wrapper(*inner_args, **inner_kwargs)\r\n 429 else deprecation_addendum,\r\n 430 **kwargs)\r\n--\u003e 431 return func(*inner_args, **inner_kwargs)\r\n 432 \r\n 433 return wrapper\r\n\r\nmpl_toolkits/mplot3d/art3d.py in do_3d_projection(self, renderer)\r\n 615 \r\n 616 if len(self._linewidths3d) \u003e 1:\r\n--\u003e 617 self._linewidths = self._linewidths3d[z_markers_idx]\r\n 618 \r\n 619 # Re-order items\r\n\r\nTypeError: only integer scalar arrays can be converted to a scalar index\r\n```\r\n\r\ngets raised, from:\r\n\r\nhttps://github.com/matplotlib/matplotlib/blob/0d433b4bf20bfc564400f35ce9709f7596e0e5f6/lib/mpl_toolkits/mplot3d/art3d.py#L599-L603\r\n\r\nThis is because the type of `self._sizes3d` is `numpy.ndarray`, but type of `self._linewidths3d` is `list`.\r\n\r\n### Expected outcome\r\n\r\nArray-like linewidth works for 3d plots as it does for 2d plots.\r\n\r\n### Additional information\r\n\r\n- `ax.scatter(x, x, x, marker='o', s=x)` works fine.\r\n- `linewidths` is a list regardless of user input type.\r\n- I don't know where linewidths gets converted to a list, but a quick fix is as simple as wrapping it in `np.array` call: `self._linewidths = np.array(self._linewidths3d)[z_markers_idx]` (tested that this fixes the issue).\r\n\r\n### Operating system\r\n\r\n_No response_\r\n\r\n### Matplotlib Version\r\n\r\n3.5.2 but also happens with older versions (3.3.x)\r\n\r\n### Matplotlib Backend\r\n\r\n_No response_\r\n\r\n### Python version\r\n\r\n_No response_\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/krassowski","@type":"Person","name":"krassowski"},"datePublished":"2022-07-16T11:21:27.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/23433/matplotlib/issues/23433"}
| 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:27c35304-359d-4b05-698b-0e1e14fec5fe |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A9CA:2D422D:1BE3436:25C3209:6A524B3B |
| html-safe-nonce | b55eef72482aadf384070260848e75f02bbb73b89339cbfba3219f6a13a20544 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOUNBOjJENDIyRDoxQkUzNDM2OjI1QzMyMDk6NkE1MjRCM0IiLCJ2aXNpdG9yX2lkIjoiMjM4NTY4MzMwMDUyNDExNjc5NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a02b266d986b016aa35f3de9728a0f3999543e75bf70c20a1064570a194bb53d |
| hovercard-subject-tag | issue:1306782439 |
| 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/23433/issue_layout |
| twitter:image | https://opengraph.githubassets.com/738bbf3e1737cd544d265cb88198a08e014c061f4b9cee873d72cf00cd4386f0/matplotlib/matplotlib/issues/23433 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/738bbf3e1737cd544d265cb88198a08e014c061f4b9cee873d72cf00cd4386f0/matplotlib/matplotlib/issues/23433 |
| og:image:alt | Bug summary The documentation says that linewidths can be float or array-like and it defaults to 1.5, but passing an array-like leads to an error Code for reproduction import matplotlib.pyplot as p... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | krassowski |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width