@@ -2893,6 +2893,7 @@ class AutoMinorLocator(Locator):
2893
2893
Dynamically find minor tick positions based on the positions of
2894
2894
major ticks. The scale must be linear with major ticks evenly spaced.
2895
2895
"""
2896
+
2896
2897
def __init__ (self , n = None ):
2897
2898
"""
2898
2899
*n* is the number of subdivisions of the interval between
@@ -2908,47 +2909,33 @@ def __init__(self, n=None):
2908
2909
self .ndivs = n
2909
2910
2910
2911
def __call__ (self ):
2911
- """Return the locations of the ticks."""
2912
+ # docstring inherited
2912
2913
if self .axis .get_scale () == 'log' :
2913
- _api .warn_external ('AutoMinorLocator does not work with '
2914
- 'logarithmic scale' )
2914
+ _api .warn_external ('AutoMinorLocator does not work on logarithmic scales' )
2915
2915
return []
2916
2916
2917
2917
majorlocs = self .axis .get_majorticklocs ()
2918
- try :
2919
- majorstep = majorlocs [1 ] - majorlocs [0 ]
2920
- except IndexError :
2921
- # Need at least two major ticks to find minor tick locations
2922
- # TODO: Figure out a way to still be able to display minor
2923
- # ticks without two major ticks visible. For now, just display
2924
- # no ticks at all.
2918
+ if len (majorlocs ) < 2 :
2919
+ # Need at least two major ticks to find minor tick locations.
2920
+ # TODO: Figure out a way to still be able to display minor ticks with less
2921
+ # than two major ticks visible. For now, just display no ticks at all.
2925
2922
return []
2923
+ majorstep = majorlocs [1 ] - majorlocs [0 ]
2926
2924
2927
2925
if self .ndivs is None :
2928
-
2929
- if self .axis .axis_name == 'y' :
2930
- self .ndivs = mpl .rcParams ['ytick.minor.ndivs' ]
2931
- else :
2932
- # for x and z axis
2933
- self .ndivs = mpl .rcParams ['xtick.minor.ndivs' ]
2926
+ self .ndivs = mpl .rcParams [
2927
+ 'ytick.minor.ndivs' if self .axis .axis_name == 'y'
2928
+ else 'xtick.minor.ndivs' ] # for x and z axis
2934
2929
2935
2930
if self .ndivs == 'auto' :
2936
-
2937
- majorstep_no_exponent = 10 ** (np .log10 (majorstep ) % 1 )
2938
-
2939
- if np .isclose (majorstep_no_exponent , [1.0 , 2.5 , 5.0 , 10.0 ]).any ():
2940
- ndivs = 5
2941
- else :
2942
- ndivs = 4
2931
+ majorstep_mantissa = 10 ** (np .log10 (majorstep ) % 1 )
2932
+ ndivs = 5 if np .isclose (majorstep_mantissa , [1 , 2.5 , 5 , 10 ]).any () else 4
2943
2933
else :
2944
2934
ndivs = self .ndivs
2945
2935
2946
2936
minorstep = majorstep / ndivs
2947
2937
2948
- vmin , vmax = self .axis .get_view_interval ()
2949
- if vmin > vmax :
2950
- vmin , vmax = vmax , vmin
2951
-
2938
+ vmin , vmax = sorted (self .axis .get_view_interval ())
2952
2939
t0 = majorlocs [0 ]
2953
2940
tmin = round ((vmin - t0 ) / minorstep )
2954
2941
tmax = round ((vmax - t0 ) / minorstep ) + 1
@@ -2957,5 +2944,5 @@ def __call__(self):
2957
2944
return self .raise_if_exceeds (locs )
2958
2945
2959
2946
def tick_values (self , vmin , vmax ):
2960
- raise NotImplementedError ('Cannot get tick locations for a '
2961
- '%s type.' % type (self ))
2947
+ raise NotImplementedError (
2948
+ f"Cannot get tick locations for a { type (self ). __name__ } " )
0 commit comments