-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Open
Labels
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.
Code for reproduction
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import art3d
fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")
edges = [
[[0.25, -0.25, 0.0], [0.0, -0.25, 0.0], [0.25, -0.25, 0.25], [0.25, -0.25, 0.0]],
[[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]],
[[0.25, 0.0, 0.0], [0.0, 0.0, 0.0], [0.25, 0.25, 0.25], [0.25, 0.0, 0.0]],
[[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]],
[[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]],
]
l=art3d.Line3DCollection(edges, colors="black", linewidths=1)
ax.add_collection3d(l, autolim=True)
Actual outcome
Traceback (most recent call last):
File "/local/home/lxvm/projects/autobz/mpl_mwe.py", line 16, in <module>
ax.add_collection3d(l, autolim=True)
File "/home/lxvm/.venv/mpl/lib/python3.11/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 2875, in add_collection3d
self.auto_scale_xyz(*np.array(col._segments3d).transpose(),
^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (5,) + inhomogeneous part.
Expected outcome
No error expected
Additional information
I found that autolims=False
avoids the error and that the bug is introduced in 7ee56ce.
The issue is that in this line
matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py
Line 2892 in 0a27401
self.auto_scale_xyz(*np.array(col._segments3d).transpose(), |
This broke the plotting code in the first example of the readme of the following package: https://github.com/jerjorg/SymmetryReduceBZ.jl
Operating system
Debian
Matplotlib Version
3.10.5
Matplotlib Backend
agg
Python version
3.11.2
Jupyter version
No response
Installation
pip