Skip to content

Commit 77038d3

Browse files
Fix empty plot scale handling
1 parent 5d335a3 commit 77038d3

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,6 @@ def _set_lim3d(self, axis, lower=None, upper=None, *, emit=True,
852852
if view_margin > 0 and hasattr(axis, '_scale') and axis._scale is not None:
853853
transform = axis.get_transform()
854854
inverse_trans = transform.inverted()
855-
# For log scale, need valid limits before transforming
856855
minpos = max(1e-300, abs(lower) if lower > 0 else 1e-5)
857856
lower, upper = axis._scale.limit_range_for_scale(lower, upper, minpos)
858857
lower_t, upper_t = transform.transform([lower, upper])
@@ -1136,15 +1135,20 @@ def _set_axis_scale(self, axis, get_lim, set_lim, value, **kwargs):
11361135
**kwargs
11371136
Forwarded to scale constructor.
11381137
"""
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(),
1146+
[[0, 0], [1, 1]])):
1147+
xymargin = 0.05 * 10/11
1148+
self.zz_dataLim = Bbox([[xymargin, xymargin],
1149+
[1 - xymargin, 1 - xymargin]])
1150+
self._zmargin = self._xmargin
11391151
axis._set_axes_scale(value, **kwargs)
1140-
# After setting scale, constrain limits using scale's limit_range_for_scale
1141-
if getattr(axis, '_scale', None) is not None:
1142-
vmin, vmax = get_lim()
1143-
minpos = getattr(axis, '_minpos', 1e-300)
1144-
new_vmin, new_vmax = axis._scale.limit_range_for_scale(
1145-
vmin, vmax, minpos)
1146-
if (new_vmin, new_vmax) != (vmin, vmax):
1147-
set_lim(new_vmin, new_vmax, auto=True)
11481152

11491153
def set_xscale(self, value, **kwargs):
11501154
"""

lib/mpl_toolkits/mplot3d/tests/test_axes3d.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3032,7 +3032,8 @@ def test_scale3d_default_limits(scale, expected_lims):
30323032
@check_figures_equal()
30333033
@pytest.mark.filterwarnings("ignore:Data has no positive values")
30343034
def test_scale3d_all_clipped(fig_test, fig_ref):
3035-
"""Fully clipped data (e.g. negative values on log) should look like an empty plot."""
3035+
"""Fully clipped data (e.g. negative values on log) should look like an empty plot.
3036+
"""
30363037
lims = (0.1, 10)
30373038
for ax in [fig_test.add_subplot(projection='3d'),
30383039
fig_ref.add_subplot(projection='3d')]:

0 commit comments

Comments
 (0)