Skip to content

Commit ac5e4d3

Browse files
Commonize 3D zmargin handling with x and y axes
1 parent a01f57d commit ac5e4d3

38 files changed

Lines changed: 15 additions & 30 deletions

lib/matplotlib/mpl-data/stylelib/classic.mplstyle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,9 @@ axes.prop_cycle : cycler('color', 'bgrcmyk')
216216
# single letter, long name, or
217217
# web-style hex
218218
axes.autolimit_mode : round_numbers
219-
axes.xmargin : 0 # x margin. See `axes.Axes.margins`
220-
axes.ymargin : 0 # y margin See `axes.Axes.margins`
219+
axes.xmargin : 0 # x margin. See `axes.Axes.margins`
220+
axes.ymargin : 0 # y margin. See `axes.Axes.margins`
221+
axes.zmargin : 0 # z margin. See `axes.Axes.margins`
221222
axes.spines.bottom : True
222223
axes.spines.left : True
223224
axes.spines.right : True

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,12 @@ def __init__(
153153

154154
self.xy_viewLim = Bbox.unit()
155155
self.zz_viewLim = Bbox.unit()
156-
xymargin = 0.05 * 10/11 # match mpl3.8 appearance
157-
self.xy_dataLim = Bbox([[xymargin, xymargin],
158-
[1 - xymargin, 1 - xymargin]])
156+
datalim_pad = 0.05 * 10/11 # match mpl3.8 appearance
157+
self.xy_dataLim = Bbox([[datalim_pad, datalim_pad],
158+
[1 - datalim_pad, 1 - datalim_pad]])
159159
# z-limits are encoded in the x-component of the Bbox, y is un-used
160-
self.zz_dataLim = Bbox.unit()
160+
self.zz_dataLim = Bbox([[datalim_pad, datalim_pad],
161+
[1 - datalim_pad, 1 - datalim_pad]])
161162

162163
# inhibit autoscale_view until the axes are defined
163164
# they can't be defined until Axes.__init__ has been called
@@ -1135,18 +1136,6 @@ def _set_axis_scale(self, axis, value, **kwargs):
11351136
**kwargs
11361137
Forwarded to scale constructor.
11371138
"""
1138-
# For non-linear scales on the z-axis, switch from the [0, 1] +
1139-
# margin=0 representation to the same xymargin + margin=0.05
1140-
# representation that x/y use. Both produce identical linear limits,
1141-
# but only the xymargin form has valid positive lower bounds for log
1142-
# etc. This must happen before _set_axes_scale because that triggers
1143-
# autoscale_view internally.
1144-
if (axis is self.zaxis and value != 'linear'
1145-
and np.array_equal(self.zz_dataLim.get_points(), [[0, 0], [1, 1]])):
1146-
xymargin = 0.05 * 10/11
1147-
self.zz_dataLim = Bbox([[xymargin, xymargin],
1148-
[1 - xymargin, 1 - xymargin]])
1149-
self._zmargin = self._xmargin
11501139
axis._set_axes_scale(value, **kwargs)
11511140

11521141
def set_xscale(self, value, **kwargs):
@@ -1549,16 +1538,14 @@ def shareview(self, other):
15491538
def clear(self):
15501539
# docstring inherited.
15511540
super().clear()
1552-
if self._focal_length == np.inf:
1553-
self._zmargin = mpl.rcParams['axes.zmargin']
1554-
else:
1555-
self._zmargin = 0.
1541+
self._zmargin = mpl.rcParams['axes.zmargin'] # x, y are done in super().clear()
15561542

1557-
xymargin = 0.05 * 10/11 # match mpl3.8 appearance
1558-
self.xy_dataLim = Bbox([[xymargin, xymargin],
1559-
[1 - xymargin, 1 - xymargin]])
1543+
datalim_pad = 0.05 * 10/11 # match mpl3.8 appearance
1544+
self.xy_dataLim = Bbox([[datalim_pad, datalim_pad],
1545+
[1 - datalim_pad, 1 - datalim_pad]])
15601546
# z-limits are encoded in the x-component of the Bbox, y is un-used
1561-
self.zz_dataLim = Bbox.unit()
1547+
self.zz_dataLim = Bbox([[datalim_pad, datalim_pad],
1548+
[1 - datalim_pad, 1 - datalim_pad]])
15621549
self._view_margin = 1/48 # default value to match mpl3.8
15631550
self.autoscale_view()
15641551

@@ -3228,9 +3215,6 @@ def scatter(self, xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=None,
32283215
depthshade_minalpha=depthshade_minalpha,
32293216
axlim_clip=axlim_clip,
32303217
)
3231-
if self._zmargin < 0.05 and xs.size > 0:
3232-
self.set_zmargin(0.05)
3233-
32343218
self.auto_scale_xyz(xs, ys, zs, had_data)
32353219

32363220
return patches
-11.4 KB
Loading
-7.23 KB
Loading
-14.2 KB
Loading
-4.81 KB
Loading
-12.5 KB
Loading
-5.45 KB
Loading
-13.9 KB
Loading
-9.07 KB
Loading

0 commit comments

Comments
 (0)