@@ -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 """
0 commit comments