Title: [Bug]: error using `add_collection3d` of `Line3DCollection` with `autolims=True` and lines containing different numbers of points · Issue #30418 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: error using `add_collection3d` of `Line3DCollection` with `autolims=True` and lines containing different numbers of points · Issue #30418 · matplotlib/matplotlib
X Title: [Bug]: error using `add_collection3d` of `Line3DCollection` with `autolims=True` and lines containing different numbers of points · Issue #30418 · matplotlib/matplotlib
Description: Bug summary The docs state here that Line3DCollection should work with lines containing different numbers of points. However, calling ax.add_collection3d using a Line3DCollection of lines of different lengths with default keywords errors...
Open Graph Description: Bug summary The docs state here that Line3DCollection should work with lines containing different numbers of points. However, calling ax.add_collection3d using a Line3DCollection of lines of differ...
X Description: Bug summary The docs state here that Line3DCollection should work with lines containing different numbers of points. However, calling ax.add_collection3d using a Line3DCollection of lines of differ...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/30418
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: error using `add_collection3d` of `Line3DCollection` with `autolims=True` and lines containing different numbers of points","articleBody":"### Bug summary\n\nThe docs state [here](https://matplotlib.org/stable/api/_as_gen/mpl_toolkits.mplot3d.art3d.Line3DCollection.html) that `Line3DCollection` should work with lines containing different numbers of points. However, calling `ax.add_collection3d` using a `Line3DCollection` of lines of different lengths with default keywords errors.\n\n### Code for reproduction\n\n```Python\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.mplot3d import art3d\n\nfig = plt.figure()\nax = fig.add_subplot(111, projection=\"3d\")\nedges = [\n [[0.25, -0.25, 0.0], [0.0, -0.25, 0.0], [0.25, -0.25, 0.25], [0.25, -0.25, 0.0]],\n [[0.25, 0.0, 0.0], [0.25, 0.25, 0.25], [0.25, -0.25, 0.25], [0.25, -0.25, 0.0], [0.25, 0.0, 0.0]],\n [[0.25, 0.0, 0.0], [0.0, 0.0, 0.0], [0.25, 0.25, 0.25], [0.25, 0.0, 0.0]],\n [[0.25, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, -0.25, 0.0], [0.25, -0.25, 0.0], [0.25, 0.0, 0.0]],\n [[0.0, 0.0, 0.0], [0.25, 0.25, 0.25], [0.25, -0.25, 0.25], [0.0, -0.25, 0.0], [0.0, 0.0, 0.0]],\n]\nl=art3d.Line3DCollection(edges, colors=\"black\", linewidths=1)\n\nax.add_collection3d(l, autolim=True)\n```\n\n### Actual outcome\n\n```\nTraceback (most recent call last):\n File \"/local/home/lxvm/projects/autobz/mpl_mwe.py\", line 16, in \u003cmodule\u003e\n ax.add_collection3d(l, autolim=True)\n File \"/home/lxvm/.venv/mpl/lib/python3.11/site-packages/mpl_toolkits/mplot3d/axes3d.py\", line 2875, in add_collection3d\n self.auto_scale_xyz(*np.array(col._segments3d).transpose(),\n ^^^^^^^^^^^^^^^^^^^^^^^^^\nValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (5,) + inhomogeneous part.\n```\n\n### Expected outcome\n\nNo error expected\n\n### Additional information\n\nI found that `autolims=False` avoids the error and that the bug is introduced in https://github.com/matplotlib/matplotlib/commit/7ee56ce31f3c2719ee774132ed36f5b1ca549afa.\nThe issue is that in this line https://github.com/matplotlib/matplotlib/blob/0a27401ecdede3081f05903e7b9b4c8531248c39/lib/mpl_toolkits/mplot3d/axes3d.py#L2892 the casting of the input lines as a Numpy array doesn't work for lines with different lengths (ragged arrays), which should be supported according to the docs.\nThis broke the plotting code in the first example of the readme of the following package: https://github.com/jerjorg/SymmetryReduceBZ.jl\n\n### Operating system\n\nDebian\n\n### Matplotlib Version\n\n3.10.5\n\n### Matplotlib Backend\n\nagg\n\n### Python version\n\n3.11.2\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\npip","author":{"url":"https://github.com/lxvm","@type":"Person","name":"lxvm"},"datePublished":"2025-08-12T17:17:49.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/30418/matplotlib/issues/30418"}
| 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:6bb7bf0c-7ee9-dd65-2c90-2fc069801aa5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A58E:255ABB:58B94:794C3:6A525612 |
| html-safe-nonce | 3d4153587573a17ff5083d25be00867874acc45725978679b0db10a7a7ad87ee |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNThFOjI1NUFCQjo1OEI5NDo3OTRDMzo2QTUyNTYxMiIsInZpc2l0b3JfaWQiOiIxMzU2NTQwNjEwMTk5MzExODkwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 23d1f867f8e93e38776eb4fb3eb152f7dd639adc8b27d513bb5734d9fa73f748 |
| hovercard-subject-tag | issue:3315157116 |
| 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/30418/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fec48fac0b7543f57d4522e2f897e3a2632122b263fe49fbe97b4227ab80cb8d/matplotlib/matplotlib/issues/30418 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fec48fac0b7543f57d4522e2f897e3a2632122b263fe49fbe97b4227ab80cb8d/matplotlib/matplotlib/issues/30418 |
| og:image:alt | Bug summary The docs state here that Line3DCollection should work with lines containing different numbers of points. However, calling ax.add_collection3d using a Line3DCollection of lines of differ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | lxvm |
| 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