@@ -989,7 +989,7 @@ def __call__(self, x, pos=None):
989989 b = self ._base
990990 # only label the decades
991991 fx = math .log (x ) / math .log (b )
992- is_x_decade = is_close_to_int (fx )
992+ is_x_decade = _is_close_to_int (fx )
993993 exponent = round (fx ) if is_x_decade else np .floor (fx )
994994 coeff = round (b ** (fx - exponent ))
995995
@@ -1073,7 +1073,7 @@ def __call__(self, x, pos=None):
10731073
10741074 # only label the decades
10751075 fx = math .log (x ) / math .log (b )
1076- is_x_decade = is_close_to_int (fx )
1076+ is_x_decade = _is_close_to_int (fx )
10771077 exponent = round (fx ) if is_x_decade else np .floor (fx )
10781078 coeff = round (b ** (fx - exponent ))
10791079 if is_x_decade :
@@ -1109,7 +1109,7 @@ def _non_decade_format(self, sign_string, base, fx, usetex):
11091109 b = float (base )
11101110 exponent = math .floor (fx )
11111111 coeff = b ** (fx - exponent )
1112- if is_close_to_int (coeff ):
1112+ if _is_close_to_int (coeff ):
11131113 coeff = round (coeff )
11141114 return r'$\mathdefault{%s%g\times%s^{%d}}$' \
11151115 % (sign_string , coeff , base , exponent )
@@ -1213,9 +1213,10 @@ def set_locs(self, locs):
12131213 if not self ._minor :
12141214 return None
12151215 if all (
1216- is_decade (x , rtol = 1e-7 )
1217- or is_decade (1 - x , rtol = 1e-7 )
1218- or (is_close_to_int (2 * x ) and int (np .round (2 * x )) == 1 )
1216+ _is_decade (x , rtol = 1e-7 )
1217+ or _is_decade (1 - x , rtol = 1e-7 )
1218+ or (_is_close_to_int (2 * x ) and
1219+ int (np .round (2 * x )) == 1 )
12191220 for x in locs
12201221 ):
12211222 # minor ticks are subsample from ideal, so no label
@@ -1262,7 +1263,7 @@ def _format_value(self, x, locs, sci_notation=True):
12621263 precision = - np .log10 (diff ) + exponent
12631264 precision = (
12641265 int (np .round (precision ))
1265- if is_close_to_int (precision )
1266+ if _is_close_to_int (precision )
12661267 else math .ceil (precision )
12671268 )
12681269 if precision < min_precision :
@@ -1284,13 +1285,13 @@ def __call__(self, x, pos=None):
12841285 return ""
12851286 if x <= 0 or x >= 1 :
12861287 return ""
1287- if is_close_to_int (2 * x ) and round (2 * x ) == 1 :
1288+ if _is_close_to_int (2 * x ) and round (2 * x ) == 1 :
12881289 s = self ._one_half
1289- elif x < 0.5 and is_decade (x , rtol = 1e-7 ):
1290- exponent = round (np .log10 (x ))
1290+ elif x < 0.5 and _is_decade (x , rtol = 1e-7 ):
1291+ exponent = round (math .log10 (x ))
12911292 s = "10^{%d}" % exponent
1292- elif x > 0.5 and is_decade (1 - x , rtol = 1e-7 ):
1293- exponent = round (np .log10 (1 - x ))
1293+ elif x > 0.5 and _is_decade (1 - x , rtol = 1e-7 ):
1294+ exponent = round (math .log10 (1 - x ))
12941295 s = self ._one_minus ("10^{%d}" % exponent )
12951296 elif x < 0.1 :
12961297 s = self ._format_value (x , self .locs )
@@ -2146,6 +2147,7 @@ def view_limits(self, dmin, dmax):
21462147 return dmin , dmax
21472148
21482149
2150+ @_api .deprecated ("3.6" )
21492151def is_decade (x , base = 10 , * , rtol = 1e-10 ):
21502152 if not np .isfinite (x ):
21512153 return False
@@ -2155,6 +2157,19 @@ def is_decade(x, base=10, *, rtol=1e-10):
21552157 return is_close_to_int (lx , atol = rtol )
21562158
21572159
2160+ def _is_decade (x , * , base = 10 , rtol = None ):
2161+ """Return True if *x* is an integer power of *base*."""
2162+ if not np .isfinite (x ):
2163+ return False
2164+ if x == 0.0 :
2165+ return True
2166+ lx = np .log (abs (x )) / np .log (base )
2167+ if rtol is None :
2168+ return np .isclose (lx , np .round (lx ))
2169+ else :
2170+ return np .isclose (lx , np .round (lx ), rtol = rtol )
2171+
2172+
21582173def _decade_less_equal (x , base ):
21592174 """
21602175 Return the largest integer power of *base* that's less or equal to *x*.
@@ -2205,10 +2220,15 @@ def _decade_greater(x, base):
22052220 return greater
22062221
22072222
2223+ @_api .deprecated ("3.6" )
22082224def is_close_to_int (x , * , atol = 1e-10 ):
22092225 return abs (x - np .round (x )) < atol
22102226
22112227
2228+ def _is_close_to_int (x ):
2229+ return math .isclose (x , round (x ))
2230+
2231+
22122232class LogLocator (Locator ):
22132233 """
22142234 Determine the tick locations for log axes
0 commit comments