161
161
from matplotlib import rcParams
162
162
from matplotlib import cbook
163
163
from matplotlib import transforms as mtransforms
164
+ from matplotlib .cbook import mplDeprecation
164
165
165
166
import warnings
166
167
@@ -1323,23 +1324,12 @@ def view_limits(self, dmin, dmax):
1323
1324
1324
1325
1325
1326
def scale_range (vmin , vmax , n = 1 , threshold = 100 ):
1326
- dv = abs (vmax - vmin )
1327
- if dv == 0 : # maxabsv == 0 is a special case of this.
1328
- return 1.0 , 0.0
1329
- # Note: this should never occur because
1330
- # vmin, vmax should have been checked by nonsingular(),
1331
- # and spread apart if necessary.
1332
- meanv = 0.5 * (vmax + vmin )
1333
- if abs (meanv ) / dv < threshold :
1334
- offset = 0
1335
- elif meanv > 0 :
1336
- ex = divmod (math .log10 (meanv ), 1 )[0 ]
1337
- offset = 10 ** ex
1338
- else :
1339
- ex = divmod (math .log10 (- meanv ), 1 )[0 ]
1340
- offset = - 10 ** ex
1341
- ex = divmod (math .log10 (dv / n ), 1 )[0 ]
1342
- scale = 10 ** ex
1327
+ dv = abs (vmax - vmin ) # > 0 as nonsingular is called before.
1328
+ meanv = (vmax + vmin ) / 2
1329
+ offset = (math .copysign (10 ** (math .log10 (abs (meanv )) // 1 ), meanv )
1330
+ if abs (meanv ) / dv >= threshold
1331
+ else 0 )
1332
+ scale = 10 ** (math .log10 (dv / n ) // 1 )
1343
1333
return scale , offset
1344
1334
1345
1335
@@ -1349,7 +1339,6 @@ class MaxNLocator(Locator):
1349
1339
"""
1350
1340
default_params = dict (nbins = 10 ,
1351
1341
steps = None ,
1352
- trim = True ,
1353
1342
integer = False ,
1354
1343
symmetric = False ,
1355
1344
prune = None )
@@ -1385,9 +1374,6 @@ def __init__(self, *args, **kwargs):
1385
1374
will be removed. If prune==None, no ticks will be removed.
1386
1375
1387
1376
"""
1388
- # I left "trim" out; it defaults to True, and it is not
1389
- # clear that there is any use case for False, so we may
1390
- # want to remove that kwarg. EF 2010/04/18
1391
1377
if args :
1392
1378
kwargs ['nbins' ] = args [0 ]
1393
1379
if len (args ) > 1 :
@@ -1403,7 +1389,8 @@ def set_params(self, **kwargs):
1403
1389
if self ._nbins != 'auto' :
1404
1390
self ._nbins = int (self ._nbins )
1405
1391
if 'trim' in kwargs :
1406
- self ._trim = kwargs ['trim' ]
1392
+ warnings .warn ("The 'trim' keyword has no effect anymore" ,
1393
+ mplDeprecation )
1407
1394
if 'integer' in kwargs :
1408
1395
self ._integer = kwargs ['integer' ]
1409
1396
if 'symmetric' in kwargs :
@@ -1446,14 +1433,14 @@ def bin_boundaries(self, vmin, vmax):
1446
1433
if step < scaled_raw_step :
1447
1434
continue
1448
1435
step *= scale
1449
- best_vmin = step * divmod ( vmin , step )[ 0 ]
1436
+ best_vmin = vmin // step * step
1450
1437
best_vmax = best_vmin + step * nbins
1451
- if ( best_vmax >= vmax ) :
1438
+ if best_vmax >= vmax :
1452
1439
break
1453
- if self . _trim :
1454
- extra_bins = int ( divmod (( best_vmax - vmax ), step )[ 0 ])
1455
- nbins -= extra_bins
1456
- return ( np . arange ( nbins + 1 ) * step + best_vmin + offset )
1440
+
1441
+ bounds = np . arange ( nbins + 1 ) * step + best_vmin
1442
+ bounds = bounds [( bounds >= vmin ) & ( bounds <= vmax )]
1443
+ return bounds + offset
1457
1444
1458
1445
def __call__ (self ):
1459
1446
vmin , vmax = self .axis .get_view_interval ()
0 commit comments