Skip to content

Commit 677e79b

Browse files
committed
Review comment - use np.split + np.cumsum
1 parent 8244c07 commit 677e79b

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,8 @@ def set_segments(self, segments):
245245
self._segments3d_data[:, 3] = 1
246246

247247
# For coveniency, store a view of the array in the original shape
248-
cum_s = 0
249-
for s in self._seg_sizes:
250-
self._segments3d.append(
251-
self._segments3d_data[cum_s:cum_s + s, :3])
252-
cum_s += s
248+
self._segments3d = np.split(self._segments3d_data[:, :3],
249+
np.cumsum(self._seg_sizes))
253250
else:
254251
self._seg_sizes = np.array([])
255252

@@ -262,11 +259,8 @@ def do_3d_projection(self, renderer):
262259
if len(self._segments3d) == 0:
263260
return 1e9
264261
xys = proj3d.proj_transform_vec(self._segments3d_data.T, renderer.M).T
265-
segments_2d = []
266-
cum_s = 0
267-
for s in self._seg_sizes:
268-
segments_2d.append(xys[cum_s:cum_s + s, :2])
269-
cum_s += s
262+
segments_2d = np.split(xys[:, :2],
263+
np.cumsum(self._seg_sizes))
270264
LineCollection.set_segments(self, segments_2d)
271265
minz = np.min(xys[:, 2])
272266
return minz

0 commit comments

Comments
 (0)