I am trying to draw and modify a collection of 3D lines. The Line3DCollection plots ok, but when I go to access the line segments, the get_segments() method returns an empty list. This behavior is the opposite of the 2D case where a LineCollection get_segment() methods gives me the list of line segments as I want.
Here is the code to reproduce this error. I ran each block in a jupyter notebook cell:
import matplotlib.pyplot as plt
from matplotlib.collections import LineCollection
from mpl_toolkits.mplot3d.art3d import Line3DCollection
# 3d example which does not work
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
lines = [
[(0,0,0), (1,1,0)],
[(0,0,0), (-1,1,0)]
]
col = Line3DCollection(lines)
ax.add_collection(col) # same result using add_collection3d()
print(col.get_segments()) # []??????
# 2D example which works
fig = plt.figure()
ax = fig.add_subplot()
lines = [
[(0,0), (1,1)],
[(0,0), (-1,1)]
]
col = LineCollection(lines)
ax.add_collection(col)
print(col.get_segments()) # a list of segments, as expected
My environment: python=3.9, matplotlib=3.5.1
Why is this happening?