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