Skip to content

Commit 3050aae

Browse files
Code review updates
1 parent 418a488 commit 3050aae

3 files changed

Lines changed: 23 additions & 38 deletions

File tree

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,7 @@ def draw(self, renderer):
337337
dtype=float, mask=mask).filled(np.nan)
338338
else:
339339
xs3d, ys3d, zs3d = self._verts3d
340-
xs, ys, zs, tis = proj3d._scale_proj_transform_clip(
341-
xs3d, ys3d, zs3d, self.axes)
340+
xs, ys, zs, tis = proj3d._scale_proj_transform_clip(xs3d, ys3d, zs3d, self.axes)
342341
self.set_data(xs, ys)
343342
super().draw(renderer)
344343
self.stale = False
@@ -521,8 +520,7 @@ def do_3d_projection(self):
521520
mask = mask | viewlim_mask
522521

523522
xyzs = np.ma.array(
524-
proj3d._scale_proj_transform_vectors(segments, self.axes),
525-
mask=mask)
523+
proj3d._scale_proj_transform_vectors(segments, self.axes), mask=mask)
526524
segments_2d = xyzs[..., 0:2]
527525
LineCollection.set_segments(self, segments_2d)
528526

@@ -605,8 +603,7 @@ def do_3d_projection(self):
605603
dtype=float, mask=mask).filled(np.nan)
606604
else:
607605
xs, ys, zs = zip(*s)
608-
vxs, vys, vzs, vis = proj3d._scale_proj_transform_clip(
609-
xs, ys, zs, self.axes)
606+
vxs, vys, vzs, vis = proj3d._scale_proj_transform_clip(xs, ys, zs, self.axes)
610607
self._path2d = mpath.Path(np.ma.column_stack([vxs, vys]))
611608
return min(vzs)
612609

@@ -666,8 +663,7 @@ def do_3d_projection(self):
666663
dtype=float, mask=mask).filled(np.nan)
667664
else:
668665
xs, ys, zs = zip(*s)
669-
vxs, vys, vzs, vis = proj3d._scale_proj_transform_clip(
670-
xs, ys, zs, self.axes)
666+
vxs, vys, vzs, vis = proj3d._scale_proj_transform_clip(xs, ys, zs, self.axes)
671667
self._path2d = mpath.Path(np.ma.column_stack([vxs, vys]), self._code3d)
672668
return min(vzs)
673669

@@ -810,8 +806,7 @@ def do_3d_projection(self):
810806
xs, ys, zs = np.ma.array(self._offsets3d, mask=mask)
811807
else:
812808
xs, ys, zs = self._offsets3d
813-
vxs, vys, vzs, vis = proj3d._scale_proj_transform_clip(
814-
xs, ys, zs, self.axes)
809+
vxs, vys, vzs, vis = proj3d._scale_proj_transform_clip(xs, ys, zs, self.axes)
815810
self._vzs = vzs
816811
if np.ma.isMA(vxs):
817812
super().set_offsets(np.ma.column_stack([vxs, vys]))
@@ -1027,8 +1022,7 @@ def do_3d_projection(self):
10271022
xyzs = np.ma.array(self._offsets3d, mask=mask)
10281023
else:
10291024
xyzs = self._offsets3d
1030-
vxs, vys, vzs, vis = proj3d._scale_proj_transform_clip(
1031-
*xyzs, self.axes)
1025+
vxs, vys, vzs, vis = proj3d._scale_proj_transform_clip(*xyzs, self.axes)
10321026
self._data_scale = _get_data_scale(vxs, vys, vzs)
10331027
# Sort the points based on z coordinates
10341028
# Performance optimization: Create a sorted index array and reorder
@@ -1362,8 +1356,7 @@ def do_3d_projection(self):
13621356
# Some faces might contain masked vertices, so we want to ignore any
13631357
# errors that those might cause
13641358
with np.errstate(invalid='ignore', divide='ignore'):
1365-
pfaces = proj3d._scale_proj_transform_vectors(
1366-
self._faces, self.axes)
1359+
pfaces = proj3d._scale_proj_transform_vectors(self._faces, self.axes)
13671360

13681361
if self._axlim_clip:
13691362
viewlim_mask = _viewlim_mask(self._faces[..., 0], self._faces[..., 1],

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,8 @@ def set_zbound(self, lower=None, upper=None, view_margin=None):
822822
lower, upper, view_margin)
823823

824824
def _set_lim3d(self, axis, lower=None, upper=None, *, emit=True,
825-
auto=False, view_margin=None, axmin=None, axmax=None):
825+
auto=False, view_margin=None, axmin=None, axmax=None,
826+
minpos=np.inf):
826827
"""
827828
Set 3D axis limits.
828829
"""
@@ -852,7 +853,6 @@ def _set_lim3d(self, axis, lower=None, upper=None, *, emit=True,
852853
if view_margin > 0 and hasattr(axis, '_scale') and axis._scale is not None:
853854
transform = axis.get_transform()
854855
inverse_trans = transform.inverted()
855-
minpos = max(1e-300, abs(lower) if lower > 0 else 1e-5)
856856
lower, upper = axis._scale.limit_range_for_scale(lower, upper, minpos)
857857
lower_t, upper_t = transform.transform([lower, upper])
858858
delta = (upper_t - lower_t) * view_margin
@@ -935,7 +935,8 @@ def set_xlim(self, left=None, right=None, *, emit=True, auto=False,
935935
>>> set_xlim(5000, 0)
936936
"""
937937
return self._set_lim3d(self.xaxis, left, right, emit=emit, auto=auto,
938-
view_margin=view_margin, axmin=xmin, axmax=xmax)
938+
view_margin=view_margin, axmin=xmin, axmax=xmax,
939+
minpos=self.xy_dataLim.minposx)
939940

940941
def set_ylim(self, bottom=None, top=None, *, emit=True, auto=False,
941942
view_margin=None, ymin=None, ymax=None):
@@ -1007,7 +1008,8 @@ def set_ylim(self, bottom=None, top=None, *, emit=True, auto=False,
10071008
>>> set_ylim(5000, 0)
10081009
"""
10091010
return self._set_lim3d(self.yaxis, bottom, top, emit=emit, auto=auto,
1010-
view_margin=view_margin, axmin=ymin, axmax=ymax)
1011+
view_margin=view_margin, axmin=ymin, axmax=ymax,
1012+
minpos=self.xy_dataLim.minposy)
10111013

10121014
def set_zlim(self, bottom=None, top=None, *, emit=True, auto=False,
10131015
view_margin=None, zmin=None, zmax=None):
@@ -1079,7 +1081,8 @@ def set_zlim(self, bottom=None, top=None, *, emit=True, auto=False,
10791081
>>> set_zlim(5000, 0)
10801082
"""
10811083
return self._set_lim3d(self.zaxis, bottom, top, emit=emit, auto=auto,
1082-
view_margin=view_margin, axmin=zmin, axmax=zmax)
1084+
view_margin=view_margin, axmin=zmin, axmax=zmax,
1085+
minpos=self.zz_dataLim.minposx)
10831086

10841087
set_xlim3d = set_xlim
10851088
set_ylim3d = set_ylim
@@ -1118,18 +1121,14 @@ def get_zlim(self):
11181121
get_zscale = _axis_method_wrapper("zaxis", "get_scale")
11191122

11201123
# Custom scale setters that handle limit validation for non-linear scales
1121-
def _set_axis_scale(self, axis, get_lim, set_lim, value, **kwargs):
1124+
def _set_axis_scale(self, axis, value, **kwargs):
11221125
"""
11231126
Set scale for an axis and constrain limits to valid range.
11241127
11251128
Parameters
11261129
----------
11271130
axis : Axis
11281131
The axis to set the scale on.
1129-
get_lim : callable
1130-
Function to get current axis limits.
1131-
set_lim : callable
1132-
Function to set axis limits.
11331132
value : str
11341133
The scale name.
11351134
**kwargs
@@ -1142,8 +1141,7 @@ def _set_axis_scale(self, axis, get_lim, set_lim, value, **kwargs):
11421141
# etc. This must happen before _set_axes_scale because that triggers
11431142
# autoscale_view internally.
11441143
if (axis is self.zaxis and value != 'linear'
1145-
and np.array_equal(self.zz_dataLim.get_points(),
1146-
[[0, 0], [1, 1]])):
1144+
and np.array_equal(self.zz_dataLim.get_points(), [[0, 0], [1, 1]])):
11471145
xymargin = 0.05 * 10/11
11481146
self.zz_dataLim = Bbox([[xymargin, xymargin],
11491147
[1 - xymargin, 1 - xymargin]])
@@ -1164,8 +1162,7 @@ def set_xscale(self, value, **kwargs):
11641162
Keyword arguments are forwarded to the scale class.
11651163
For example, ``base=2`` can be passed when using a log scale.
11661164
"""
1167-
self._set_axis_scale(self.xaxis, self.get_xlim, self.set_xlim,
1168-
value, **kwargs)
1165+
self._set_axis_scale(self.xaxis, value, **kwargs)
11691166

11701167
def set_yscale(self, value, **kwargs):
11711168
"""
@@ -1181,8 +1178,7 @@ def set_yscale(self, value, **kwargs):
11811178
Keyword arguments are forwarded to the scale class.
11821179
For example, ``base=2`` can be passed when using a log scale.
11831180
"""
1184-
self._set_axis_scale(self.yaxis, self.get_ylim, self.set_ylim,
1185-
value, **kwargs)
1181+
self._set_axis_scale(self.yaxis, value, **kwargs)
11861182

11871183
def set_zscale(self, value, **kwargs):
11881184
"""
@@ -1198,8 +1194,7 @@ def set_zscale(self, value, **kwargs):
11981194
Keyword arguments are forwarded to the scale class.
11991195
For example, ``base=2`` can be passed when using a log scale.
12001196
"""
1201-
self._set_axis_scale(self.zaxis, self.get_zlim, self.set_zlim,
1202-
value, **kwargs)
1197+
self._set_axis_scale(self.zaxis, value, **kwargs)
12031198

12041199
get_zticks = _axis_method_wrapper("zaxis", "get_ticklocs")
12051200
set_zticks = _axis_method_wrapper("zaxis", "set_ticks")
@@ -1421,10 +1416,7 @@ def get_proj(self):
14211416
# transformation maps transformed coordinates (not data coordinates)
14221417
# to the unit cube
14231418
scaled_limits = self._get_scaled_limits()
1424-
worldM = proj3d.world_transformation(
1425-
*scaled_limits,
1426-
pb_aspect=box_aspect,
1427-
)
1419+
worldM = proj3d.world_transformation(*scaled_limits, pb_aspect=box_aspect)
14281420

14291421
# Look into the middle of the world coordinates:
14301422
R = 0.5 * box_aspect

lib/mpl_toolkits/mplot3d/axis3d.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def _move_from_center(coord, centers, deltas, axmask=(True, True, True)):
2222
return coord + axmask * np.copysign(1, coord - centers) * deltas
2323

2424

25-
2625
def _tick_update_position(tick, tickxs, tickys, labelpos):
2726
"""Update tick line and label position and style."""
2827

@@ -274,7 +273,8 @@ def _get_coord_info(self):
274273
maxs = np.array([xmax, ymax, zmax])
275274

276275
# Get data-space bounds for _transformed_cube
277-
bounds = (*self.axes.get_xbound(), *self.axes.get_ybound(),
276+
bounds = (*self.axes.get_xbound(),
277+
*self.axes.get_ybound(),
278278
*self.axes.get_zbound())
279279
bounds_proj = self.axes._transformed_cube(bounds)
280280

0 commit comments

Comments
 (0)