Skip to content

Commit 32722d9

Browse files
scottshambaughkyracho
authored andcommitted
Code review comments on 3D axlim clipping
1 parent f8e742b commit 32722d9

File tree

4 files changed

+27
-24
lines changed

4 files changed

+27
-24
lines changed

lib/matplotlib/collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def _prepare_points(self):
339339
# This might have changed an ndarray into a masked array.
340340
offset_trf = offset_trf.get_affine()
341341

342-
if np.ma.isMaskedArray(offsets):
342+
if isinstance(offsets, np.ma.MaskedArray):
343343
offsets = offsets.filled(np.nan)
344344
# Changing from a masked array to nan-filled ndarray
345345
# is probably most efficient at this point.

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,11 @@ def do_3d_projection(self):
452452
"""
453453
segments = self._segments3d
454454
if self._axlim_clip:
455-
segments = [np.ma.column_stack([*_viewlim_mask(*zip(*points), self.axes)])
456-
for points in segments]
455+
all_points = np.ma.vstack(segments)
456+
masked_points = np.ma.column_stack([*_viewlim_mask(*all_points.T,
457+
self.axes)])
458+
segment_lengths = [segment.shape[0] for segment in segments]
459+
segments = np.split(masked_points, np.cumsum(segment_lengths[:-1]))
457460
xyslist = [proj3d._proj_trans_points(points, self.axes.M)
458461
for points in segments]
459462
segments_2d = [np.ma.column_stack([xs, ys]) for xs, ys, zs in xyslist]

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,10 +2594,10 @@ def contour(self, X, Y, Z, *args,
25942594
offset : float, optional
25952595
If specified, plot a projection of the contour lines at this
25962596
position in a plane normal to *zdir*.
2597-
data : indexable object, optional
2598-
DATA_PARAMETER_PLACEHOLDER
25992597
axlim_clip : bool, default: False
26002598
Whether to hide lines with a vertex outside the axes view limits.
2599+
data : indexable object, optional
2600+
DATA_PARAMETER_PLACEHOLDER
26012601
26022602
*args, **kwargs
26032603
Other arguments are forwarded to `matplotlib.axes.Axes.contour`.
@@ -2641,10 +2641,10 @@ def tricontour(self, *args,
26412641
offset : float, optional
26422642
If specified, plot a projection of the contour lines at this
26432643
position in a plane normal to *zdir*.
2644-
data : indexable object, optional
2645-
DATA_PARAMETER_PLACEHOLDER
26462644
axlim_clip : bool, default: False
26472645
Whether to hide lines with a vertex outside the axes view limits.
2646+
data : indexable object, optional
2647+
DATA_PARAMETER_PLACEHOLDER
26482648
*args, **kwargs
26492649
Other arguments are forwarded to `matplotlib.axes.Axes.tricontour`.
26502650
@@ -2698,10 +2698,10 @@ def contourf(self, X, Y, Z, *args,
26982698
offset : float, optional
26992699
If specified, plot a projection of the contour lines at this
27002700
position in a plane normal to *zdir*.
2701-
data : indexable object, optional
2702-
DATA_PARAMETER_PLACEHOLDER
27032701
axlim_clip : bool, default: False
27042702
Whether to hide lines with a vertex outside the axes view limits.
2703+
data : indexable object, optional
2704+
DATA_PARAMETER_PLACEHOLDER
27052705
*args, **kwargs
27062706
Other arguments are forwarded to `matplotlib.axes.Axes.contourf`.
27072707
@@ -2738,10 +2738,10 @@ def tricontourf(self, *args, zdir='z', offset=None, axlim_clip=False, **kwargs):
27382738
offset : float, optional
27392739
If specified, plot a projection of the contour lines at this
27402740
position in a plane normal to zdir.
2741-
data : indexable object, optional
2742-
DATA_PARAMETER_PLACEHOLDER
27432741
axlim_clip : bool, default: False
27442742
Whether to hide lines with a vertex outside the axes view limits.
2743+
data : indexable object, optional
2744+
DATA_PARAMETER_PLACEHOLDER
27452745
*args, **kwargs
27462746
Other arguments are forwarded to
27472747
`matplotlib.axes.Axes.tricontourf`.
@@ -2936,10 +2936,10 @@ def bar(self, left, height, zs=0, zdir='z', *args,
29362936
used for all bars.
29372937
zdir : {'x', 'y', 'z'}, default: 'z'
29382938
When plotting 2D data, the direction to use as z ('x', 'y' or 'z').
2939-
data : indexable object, optional
2940-
DATA_PARAMETER_PLACEHOLDER
29412939
axlim_clip : bool, default: False
29422940
Whether to hide bars with points outside the axes view limits.
2941+
data : indexable object, optional
2942+
DATA_PARAMETER_PLACEHOLDER
29432943
**kwargs
29442944
Other keyword arguments are forwarded to
29452945
`matplotlib.axes.Axes.bar`.
@@ -3027,12 +3027,12 @@ def bar3d(self, x, y, z, dx, dy, dz, color=None,
30273027
lightsource : `~matplotlib.colors.LightSource`, optional
30283028
The lightsource to use when *shade* is True.
30293029
3030-
data : indexable object, optional
3031-
DATA_PARAMETER_PLACEHOLDER
3032-
30333030
axlim_clip : bool, default: False
30343031
Whether to hide the bars with points outside the axes view limits.
30353032
3033+
data : indexable object, optional
3034+
DATA_PARAMETER_PLACEHOLDER
3035+
30363036
**kwargs
30373037
Any additional keyword arguments are passed onto
30383038
`~.art3d.Poly3DCollection`.
@@ -3185,12 +3185,12 @@ def quiver(self, X, Y, Z, U, V, W, *,
31853185
Whether all arrows are normalized to have the same length, or keep
31863186
the lengths defined by *u*, *v*, and *w*.
31873187
3188-
data : indexable object, optional
3189-
DATA_PARAMETER_PLACEHOLDER
3190-
31913188
axlim_clip : bool, default: False
31923189
Whether to hide arrows with points outside the axes view limits.
31933190
3191+
data : indexable object, optional
3192+
DATA_PARAMETER_PLACEHOLDER
3193+
31943194
**kwargs
31953195
Any additional keyword arguments are delegated to
31963196
:class:`.Line3DCollection`
@@ -3890,12 +3890,12 @@ def stem(self, x, y, z, *, linefmt='C0-', markerfmt='C0o', basefmt='C3-',
38903890
orientation : {'x', 'y', 'z'}, default: 'z'
38913891
The direction along which stems are drawn.
38923892
3893-
data : indexable object, optional
3894-
DATA_PARAMETER_PLACEHOLDER
3895-
38963893
axlim_clip : bool, default: False
38973894
Whether to hide stems that are outside the axes limits.
38983895
3896+
data : indexable object, optional
3897+
DATA_PARAMETER_PLACEHOLDER
3898+
38993899
Returns
39003900
-------
39013901
`.StemContainer`

lib/mpl_toolkits/mplot3d/tests/test_axes3d.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,10 +2176,10 @@ def test_computed_zorder():
21762176
ax.add_collection3d(tri)
21772177

21782178
# plot a vector
2179-
ax.plot((2, 2), (2, 2), (0, 4), c='red', zorder=2, axlim_clip=False)
2179+
ax.plot((2, 2), (2, 2), (0, 4), c='red', zorder=2)
21802180

21812181
# plot some points
2182-
ax.scatter((3, 3), (1, 3), (1, 3), c='red', zorder=10, axlim_clip=False)
2182+
ax.scatter((3, 3), (1, 3), (1, 3), c='red', zorder=10)
21832183

21842184
ax.set_xlim((0, 5.0))
21852185
ax.set_ylim((0, 5.0))

0 commit comments

Comments
 (0)