Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2890,8 +2890,10 @@ def add_collection3d(self, col, zs=0, zdir='z', autolim=True, *,

if autolim:
if isinstance(col, art3d.Line3DCollection):
self.auto_scale_xyz(*np.array(col._segments3d).transpose(),
had_data=had_data)
# Handle ragged arrays by extracting coordinates separately
all_points = np.concatenate(col._segments3d)
self.auto_scale_xyz(all_points[:, 0], all_points[:, 1],
all_points[:, 2], had_data=had_data)
elif isinstance(col, art3d.Poly3DCollection):
self.auto_scale_xyz(col._faces[..., 0],
col._faces[..., 1],
Expand Down
24 changes: 24 additions & 0 deletions lib/mpl_toolkits/mplot3d/tests/test_axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2689,3 +2689,27 @@ def test_ndarray_color_kwargs_value_error():
ax = fig.add_subplot(111, projection='3d')
ax.scatter(1, 0, 0, color=np.array([0, 0, 0, 1]))
fig.canvas.draw()


def test_line3dcollection_autolim_ragged():
"""Test Line3DCollection with autolim=True and lines of different lengths."""
fig = plt.figure()
ax = fig.add_subplot(projection='3d')

# Create lines with different numbers of points (ragged arrays)
edges = [
[(0, 0, 0), (1, 1, 1), (2, 2, 2)], # 3 points
[(0, 1, 0), (1, 2, 1)], # 2 points
[(1, 0, 1), (2, 1, 2), (3, 2, 3), (4, 3, 4)] # 4 points
]

# This should not raise an exception with the fix
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"with the fix" won't make much sense in a few month.

Suggested change
# This should not raise an exception with the fix
# This should not raise an exception.

collections = ax.add_collection3d(art3d.Line3DCollection(edges), autolim=True)

# Check that limits were computed correctly with margins
# The limits should include all points with default margins
assert np.allclose(ax.get_xlim3d(), (-0.08333333333333333, 4.083333333333333))
assert np.allclose(ax.get_ylim3d(), (-0.0625, 3.0625))
assert np.allclose(ax.get_zlim3d(), (-0.08333333333333333, 4.083333333333333))

plt.close(fig)
Comment on lines +2714 to +2715
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed; all test figures are auto-closed.

Suggested change
plt.close(fig)

Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy