Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b48cdcf

Browse files
Line3D collection and Path3DCollection masking
1 parent 606e76f commit b48cdcf

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

‎lib/mpl_toolkits/mplot3d/art3d.py‎

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -448,22 +448,27 @@ def do_3d_projection(self):
448448
"""
449449
Project the points according to renderer matrix.
450450
"""
451-
segments = self._segments3d
451+
segments = np.asanyarray(self._segments3d)
452+
453+
mask = False
454+
if np.ma.isMA(segments):
455+
mask = segments.mask
456+
452457
if self._axlim_clip:
453-
all_points = np.ma.vstack(segments)
454-
masked_points = np.ma.column_stack([*_viewlim_mask(*all_points.T,
455-
self.axes)])
456-
segment_lengths = [np.shape(segment)[0] for segment in segments]
457-
segments = np.split(masked_points, np.cumsum(segment_lengths[:-1]))
458-
xyslist = [proj3d._proj_trans_points(points, self.axes.M)
459-
for points in segments]
460-
segments_2d = [np.ma.column_stack([xs, ys]) for xs, ys, zs in xyslist]
458+
viewlim_mask = _viewlim_mask(segments[..., 0],
459+
segments[..., 1],
460+
segments[..., 2],
461+
self.axes)
462+
if np.any(viewlim_mask):
463+
# broadcast mask to 3D
464+
viewlim_mask = viewlim_mask[..., np.newaxis].repeat(3, axis=-1)
465+
mask = mask | viewlim_mask
466+
xyzs = np.ma.array(proj3d._proj_transform_vectors(segments, self.axes.M), mask=mask)
467+
segments_2d = xyzs[..., 0:2]
461468
LineCollection.set_segments(self, segments_2d)
462469

463470
# FIXME
464-
minz = 1e9
465-
for xs, ys, zs in xyslist:
466-
minz = min(minz, min(zs))
471+
minz = min(xyzs[..., 2].min(), 1e9)
467472
return minz
468473

469474

@@ -853,11 +858,17 @@ def set_depthshade(self, depthshade):
853858
self.stale = True
854859

855860
def do_3d_projection(self):
861+
mask = False
862+
for xyz in self._offsets3d:
863+
if np.ma.isMA(xyz):
864+
mask = mask | xyz.mask
856865
if self._axlim_clip:
857-
xs, ys, zs = _viewlim_mask(*self._offsets3d, self.axes)
866+
mask = mask | _viewlim_mask(*self._offsets3d, self.axes)
867+
mask = np.broadcast_to(mask, (len(self._offsets3d), *self._offsets3d[0].shape))
868+
xyzs = np.ma.array(self._offsets3d, mask=mask)
858869
else:
859-
xs, ys, zs = self._offsets3d
860-
vxs, vys, vzs, vis = proj3d._proj_transform_clip(xs, ys, zs,
870+
xyzs = self._offsets3d
871+
vxs, vys, vzs, vis = proj3d._proj_transform_clip(*xyzs,
861872
self.axes.M,
862873
self.axes._focal_length)
863874
# Sort the points based on z coordinates

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /