@@ -989,7 +989,7 @@ def __call__(self, x, pos=None):
989
989
b = self ._base
990
990
# only label the decades
991
991
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 )
993
993
exponent = round (fx ) if is_x_decade else np .floor (fx )
994
994
coeff = round (b ** (fx - exponent ))
995
995
@@ -1073,7 +1073,7 @@ def __call__(self, x, pos=None):
1073
1073
1074
1074
# only label the decades
1075
1075
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 )
1077
1077
exponent = round (fx ) if is_x_decade else np .floor (fx )
1078
1078
coeff = round (b ** (fx - exponent ))
1079
1079
if is_x_decade :
@@ -1109,7 +1109,7 @@ def _non_decade_format(self, sign_string, base, fx, usetex):
1109
1109
b = float (base )
1110
1110
exponent = math .floor (fx )
1111
1111
coeff = b ** (fx - exponent )
1112
- if is_close_to_int (coeff ):
1112
+ if _is_close_to_int (coeff ):
1113
1113
coeff = round (coeff )
1114
1114
return r'$\mathdefault{%s%g\times%s^{%d}}$' \
1115
1115
% (sign_string , coeff , base , exponent )
@@ -1213,9 +1213,10 @@ def set_locs(self, locs):
1213
1213
if not self ._minor :
1214
1214
return None
1215
1215
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 )
1219
1220
for x in locs
1220
1221
):
1221
1222
# minor ticks are subsample from ideal, so no label
@@ -1262,7 +1263,7 @@ def _format_value(self, x, locs, sci_notation=True):
1262
1263
precision = - np .log10 (diff ) + exponent
1263
1264
precision = (
1264
1265
int (np .round (precision ))
1265
- if is_close_to_int (precision )
1266
+ if _is_close_to_int (precision )
1266
1267
else math .ceil (precision )
1267
1268
)
1268
1269
if precision < min_precision :
@@ -1284,13 +1285,13 @@ def __call__(self, x, pos=None):
1284
1285
return ""
1285
1286
if x <= 0 or x >= 1 :
1286
1287
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 :
1288
1289
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 ))
1291
1292
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 ))
1294
1295
s = self ._one_minus ("10^{%d}" % exponent )
1295
1296
elif x < 0.1 :
1296
1297
s = self ._format_value (x , self .locs )
@@ -2146,6 +2147,7 @@ def view_limits(self, dmin, dmax):
2146
2147
return dmin , dmax
2147
2148
2148
2149
2150
+ @_api .deprecated ("3.6" )
2149
2151
def is_decade (x , base = 10 , * , rtol = 1e-10 ):
2150
2152
if not np .isfinite (x ):
2151
2153
return False
@@ -2155,6 +2157,19 @@ def is_decade(x, base=10, *, rtol=1e-10):
2155
2157
return is_close_to_int (lx , atol = rtol )
2156
2158
2157
2159
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
+
2158
2173
def _decade_less_equal (x , base ):
2159
2174
"""
2160
2175
Return the largest integer power of *base* that's less or equal to *x*.
@@ -2205,10 +2220,15 @@ def _decade_greater(x, base):
2205
2220
return greater
2206
2221
2207
2222
2223
+ @_api .deprecated ("3.6" )
2208
2224
def is_close_to_int (x , * , atol = 1e-10 ):
2209
2225
return abs (x - np .round (x )) < atol
2210
2226
2211
2227
2228
+ def _is_close_to_int (x ):
2229
+ return math .isclose (x , round (x ))
2230
+
2231
+
2212
2232
class LogLocator (Locator ):
2213
2233
"""
2214
2234
Determine the tick locations for log axes
0 commit comments