@@ -988,7 +988,7 @@ def __call__(self, x, pos=None):
988988 b = self ._base
989989 # only label the decades
990990 fx = math .log (x ) / math .log (b )
991- is_x_decade = is_close_to_int (fx )
991+ is_x_decade = _is_close_to_int (fx )
992992 exponent = round (fx ) if is_x_decade else np .floor (fx )
993993 coeff = round (b ** (fx - exponent ))
994994
@@ -1072,7 +1072,7 @@ def __call__(self, x, pos=None):
10721072
10731073 # only label the decades
10741074 fx = math .log (x ) / math .log (b )
1075- is_x_decade = is_close_to_int (fx )
1075+ is_x_decade = _is_close_to_int (fx )
10761076 exponent = round (fx ) if is_x_decade else np .floor (fx )
10771077 coeff = round (b ** (fx - exponent ))
10781078 if is_x_decade :
@@ -1108,7 +1108,7 @@ def _non_decade_format(self, sign_string, base, fx, usetex):
11081108 b = float (base )
11091109 exponent = math .floor (fx )
11101110 coeff = b ** (fx - exponent )
1111- if is_close_to_int (coeff ):
1111+ if _is_close_to_int (coeff ):
11121112 coeff = round (coeff )
11131113 return r'$\mathdefault{%s%g\times%s^{%d}}$' \
11141114 % (sign_string , coeff , base , exponent )
@@ -1212,9 +1212,10 @@ def set_locs(self, locs):
12121212 if not self ._minor :
12131213 return None
12141214 if all (
1215- is_decade (x , rtol = 1e-7 )
1216- or is_decade (1 - x , rtol = 1e-7 )
1217- or (is_close_to_int (2 * x ) and int (np .round (2 * x )) == 1 )
1215+ _is_decade (x , rtol = 1e-7 )
1216+ or _is_decade (1 - x , rtol = 1e-7 )
1217+ or (_is_close_to_int (2 * x ) and
1218+ int (np .round (2 * x )) == 1 )
12181219 for x in locs
12191220 ):
12201221 # minor ticks are subsample from ideal, so no label
@@ -1261,7 +1262,7 @@ def _format_value(self, x, locs, sci_notation=True):
12611262 precision = - np .log10 (diff ) + exponent
12621263 precision = (
12631264 int (np .round (precision ))
1264- if is_close_to_int (precision )
1265+ if _is_close_to_int (precision )
12651266 else math .ceil (precision )
12661267 )
12671268 if precision < min_precision :
@@ -1283,13 +1284,13 @@ def __call__(self, x, pos=None):
12831284 return ""
12841285 if x <= 0 or x >= 1 :
12851286 return ""
1286- if is_close_to_int (2 * x ) and round (2 * x ) == 1 :
1287+ if _is_close_to_int (2 * x ) and round (2 * x ) == 1 :
12871288 s = self ._one_half
1288- elif x < 0.5 and is_decade (x , rtol = 1e-7 ):
1289- exponent = round (np .log10 (x ))
1289+ elif x < 0.5 and _is_decade (x , rtol = 1e-7 ):
1290+ exponent = round (math .log10 (x ))
12901291 s = "10^{%d}" % exponent
1291- elif x > 0.5 and is_decade (1 - x , rtol = 1e-7 ):
1292- exponent = round (np .log10 (1 - x ))
1292+ elif x > 0.5 and _is_decade (1 - x , rtol = 1e-7 ):
1293+ exponent = round (math .log10 (1 - x ))
12931294 s = self ._one_minus ("10^{%d}" % exponent )
12941295 elif x < 0.1 :
12951296 s = self ._format_value (x , self .locs )
@@ -2145,6 +2146,7 @@ def view_limits(self, dmin, dmax):
21452146 return dmin , dmax
21462147
21472148
2149+ @_api .deprecated ("3.6" )
21482150def is_decade (x , base = 10 , * , rtol = 1e-10 ):
21492151 if not np .isfinite (x ):
21502152 return False
@@ -2154,6 +2156,19 @@ def is_decade(x, base=10, *, rtol=1e-10):
21542156 return is_close_to_int (lx , atol = rtol )
21552157
21562158
2159+ def _is_decade (x , * , base = 10 , rtol = None ):
2160+ """Return True if *x* is an integer power of *base*."""
2161+ if not np .isfinite (x ):
2162+ return False
2163+ if x == 0.0 :
2164+ return True
2165+ lx = np .log (abs (x )) / np .log (base )
2166+ if rtol is None :
2167+ return np .isclose (lx , np .round (lx ))
2168+ else :
2169+ return np .isclose (lx , np .round (lx ), rtol = rtol )
2170+
2171+
21572172def _decade_less_equal (x , base ):
21582173 """
21592174 Return the largest integer power of *base* that's less or equal to *x*.
@@ -2204,10 +2219,15 @@ def _decade_greater(x, base):
22042219 return greater
22052220
22062221
2222+ @_api .deprecated ("3.6" )
22072223def is_close_to_int (x , * , atol = 1e-10 ):
22082224 return abs (x - np .round (x )) < atol
22092225
22102226
2227+ def _is_close_to_int (x ):
2228+ return math .isclose (x , round (x ))
2229+
2230+
22112231class LogLocator (Locator ):
22122232 """
22132233 Determine the tick locations for log axes
0 commit comments