@@ -2792,33 +2792,46 @@ def ideal_ticks(x):
2792
2792
return MaxNLocator .tick_values (self , vmin , vmax )
2793
2793
2794
2794
def nonsingular (self , vmin , vmax ):
2795
- initial_range = (1e-7 , 1 - 1e-7 )
2796
- if not np .isfinite (vmin ) or not np .isfinite (vmax ):
2797
- return initial_range # no data plotted yet
2798
-
2795
+ standard_minpos = 1e-7
2796
+ initial_range = (standard_minpos , 1 - standard_minpos )
2797
+ swap_vlims = False
2799
2798
if vmin > vmax :
2799
+ swap_vlims = True
2800
2800
vmin , vmax = vmax , vmin
2801
-
2802
- # what to do if a window beyond ]0, 1[ is chosen
2803
- if self .axis is not None :
2804
- minpos = self .axis .get_minpos ()
2805
- if not np .isfinite (minpos ):
2806
- return initial_range # again, no data plotted
2801
+ if not np .isfinite (vmin ) or not np .isfinite (vmax ):
2802
+ vmin , vmax = initial_range # Initial range, no data plotted yet.
2803
+ elif vmax <= 0 :
2804
+ cbook ._warn_external (
2805
+ "Data has no positive values, and therefore cannot be "
2806
+ "logit-scaled."
2807
+ )
2808
+ vmin , vmax = initial_range
2809
+ elif vmin >= 1 :
2810
+ cbook ._warn_external (
2811
+ "Data has no values smaller than one, and therefore cannot "
2812
+ "be logit-scaled."
2813
+ )
2814
+ vmin , vmax = initial_range
2807
2815
else :
2808
- minpos = 1e-7 # should not occur in normal use
2809
-
2810
- # NOTE: for vmax, we should query a property similar to get_minpos, but
2811
- # related to the maximal, less-than-one data point. Unfortunately,
2812
- # Bbox._minpos is defined very deep in the BBox and updated with data,
2813
- # so for now we use 1 - minpos as a substitute.
2814
-
2815
- if vmin <= 0 :
2816
- vmin = minpos
2817
- if vmax >= 1 :
2818
- vmax = 1 - minpos
2819
- if vmin == vmax :
2820
- return 0.1 * vmin , 1 - 0.1 * vmin
2821
-
2816
+ minpos = (
2817
+ self .axis .get_minpos ()
2818
+ if self .axis is not None
2819
+ else standard_minpos
2820
+ )
2821
+ if not np .isfinite (minpos ):
2822
+ minpos = standard_minpos # This should never take effect.
2823
+ if vmin <= 0 :
2824
+ vmin = minpos
2825
+ # NOTE: for vmax, we should query a property similar to get_minpos,
2826
+ # but related to the maximal, less-than-one data point.
2827
+ # Unfortunately, Bbox._minpos is defined very deep in the BBox and
2828
+ # updated with data, so for now we use 1 - minpos as a substitute.
2829
+ if vmax >= 1 :
2830
+ vmax = 1 - minpos
2831
+ if vmin == vmax :
2832
+ vmin , vmax = 0.1 * vmin , 1 - 0.1 * vmin
2833
+ if swap_vlims :
2834
+ vmin , vmax = vmax , vmin
2822
2835
return vmin , vmax
2823
2836
2824
2837
0 commit comments