154
154
:class:`PercentFormatter`
155
155
Format labels as a percentage
156
156
157
- :class:`BinaryIntFormatter`
158
- Format labels as binary integers.
159
-
160
- :class:`HexIntFormatter`
161
- Format labels as hexadecimal integers.
157
+ :class:`IntegerFormatter`
158
+ Extension of :class:`StrMethodFormatter` to support integer formats.
162
159
163
160
:class:`LinearScaleFormatter`
164
161
Wrap another formatter to display transformed values.
204
201
'LogFormatterExponent' , 'LogFormatterMathtext' ,
205
202
'IndexFormatter' , 'LogFormatterSciNotation' ,
206
203
'LogitFormatter' , 'EngFormatter' , 'PercentFormatter' ,
207
- 'LinearScaleFormatter' , 'BinaryIntFormatter ' ,
208
- 'HexIntFormatter ' , 'Locator ' , 'IndexLocator' , 'FixedLocator ' ,
209
- 'NullLocator' , ' LinearLocator' , 'LogLocator' , 'AutoLocator' ,
204
+ 'LinearScaleFormatter' , 'IntegerFormatter' , 'Locator ' ,
205
+ 'IndexLocator ' , 'FixedLocator ' , 'NullLocator ' ,
206
+ 'LinearLocator' , 'LogLocator' , 'AutoLocator' ,
210
207
'MultipleLocator' , 'MaxNLocator' , 'AutoMinorLocator' ,
211
208
'SymmetricalLogLocator' , 'LogitLocator' )
212
209
@@ -1335,21 +1332,21 @@ def transform(self, x):
1335
1332
"""
1336
1333
Ensures that `x` is an integer.
1337
1334
1338
- If `self. unsigned` is `True`, then the integer is treated as a
1339
- positive number of size `self. bits`. If `self. bits` is `None`,
1340
- the number of bits is taken as `(-x).bit_length() - 1`.
1335
+ If in unsigned mode, the integer is treated as a positive number
1336
+ with the specified number of bits. The default number of bits is
1337
+ taken as `(-x).bit_length() + 1`.
1341
1338
1342
1339
Returns the transformed number.
1343
1340
"""
1344
1341
x = int (x )
1345
1342
if x < 0 and self ._unsigned :
1346
- bits = (- x ).bit_length () if self ._bits is None else self ._bits
1343
+ bits = (- x ).bit_length () + 1 if self ._bits is None else self ._bits
1347
1344
x = x & ((1 << bits ) - 1 )
1348
1345
return x
1349
1346
1350
1347
def __call__ (self , x , pos = None ):
1351
- return super ( IntegerFormatter , self ). __call__ ( x = self . transform ( x ),
1352
- pos = pos )
1348
+ if x < 0 : self . p = None
1349
+ return super ( IntegerFormatter , self ). __call__ ( self . transform ( x ), pos )
1353
1350
1354
1351
1355
1352
class LinearScaleFormatter (Formatter ):
@@ -1360,67 +1357,67 @@ class LinearScaleFormatter(Formatter):
1360
1357
This formatter can use any other formatter to actually render the
1361
1358
ticks.
1362
1359
1363
- inRef: number or 2-element iterable
1364
- Bounds on the input range to match to the output range. These
1365
- numbers do not actually restrict the input in any way. They are
1366
- just reference points. If the range is a scalar, it will be
1367
- interpreted as ``(0, inRef)``.
1368
- outRef: number or 2-element iterable
1369
- Bounds on the output range to match to the input range. These
1370
- numbers do not actually restrict the output in any way. They are
1371
- just reference points. If the range is a scalar, it will be
1372
- interpreted as ``(0, outRef)``.
1373
- formatter: matplotlib.ticker.Formatter
1360
+ in_start : number
1361
+ Reference point on the input domain that matches `out_start` in
1362
+ the output range. This number does not restrict the domain in
1363
+ any way. Defaults to 0.0.
1364
+ in_end : number
1365
+ Reference point on the input domain that matches `out_end` in
1366
+ the output range. This number does not restrict the domain in
1367
+ any way. Defaults to 1.0.
1368
+ out_start : number
1369
+ Reference point on the output range that matches `in_start` in
1370
+ the input domain. This number does not restrict the range in
1371
+ any way. Defaults to 0.0.
1372
+ out_end : number
1373
+ Reference point on the output range that matches `in_end` in
1374
+ the input domain. This number does not restrict the range in
1375
+ any way. Defaults to 1.0.
1376
+ formatter : matplotlib.ticker.Formatter
1374
1377
The instance to delegate the actual formatting of the
1375
1378
transformed value to. This does not have to be an instance of
1376
1379
``matplotlib.ticker.Formatter``. Any callable that accepts ``x``
1377
- and ``pos`` as arguments and returns a string will work.
1380
+ and ``pos`` as arguments and returns a string will also work.
1378
1381
"""
1379
- def __init__ (self , inRef = 1.0 , outRef = 1.0 , formatter = ScalarFormatter ()):
1380
- def unpack (ref , name ):
1381
- if np .iterable (ref ):
1382
- ref = tuple (ref )
1383
- if len (ref ) != 2 :
1384
- raise ValueError ('Expected 2-element iterable for `{}`, '
1385
- 'got {}.' .format (name , len (ref )))
1386
- return ref
1387
- return 0 , ref
1388
-
1382
+ def __init__ (self , in_start = 0.0 , in_end = 1.0 , out_start = 0.0 , out_end = 1.0 ,
1383
+ formatter = ScalarFormatter ()):
1389
1384
# All these values are retained for debugging/extension.
1390
- # Only the minima are used explicitly.
1391
- self .iMin , self .iMax = unpack (inRef , 'in' )
1392
- self .oMin , self .oMax = unpack (outRef , 'out' )
1393
- self .formatter = formatter
1385
+ # Only the starts are used explicitly.
1386
+ self ._in_start = in_start
1387
+ self ._in_end = in_end
1388
+ self ._out_start = out_start
1389
+ self ._out_end = out_end
1390
+ self ._formatter = formatter
1394
1391
1395
- # Precomputing the values that are used in addition to the minima
1396
- self .iRange = self .iMax - self .iMin
1397
- self .oRange = self .oMax - self .oMin
1392
+ # Precomputing the values that are used in addition to the starts
1393
+ self ._in_range = self ._in_end - self ._in_start
1394
+ self ._out_range = self ._out_end - self ._out_start
1398
1395
1399
1396
def transform (self , x ):
1400
1397
"""
1401
1398
Transforms a value from the input scale to the output scale.
1402
1399
"""
1403
- return (x - self .iMin ) / self .iRange * self .oRange + self .oMin
1400
+ return (x - self ._in_start ) / self ._in_range * self ._out_range + self ._out_start
1404
1401
1405
1402
def __call__ (self , x , pos = None ):
1406
- return self .formatter (self .transform (x ), pos )
1403
+ return self ._formatter (self .transform (x ), pos )
1407
1404
1408
1405
def set_axis (self , ax ):
1409
- if hasattr (self .formatter , 'set_axis' ):
1410
- self .formatter .set_axis (ax )
1406
+ if hasattr (self ._formatter , 'set_axis' ):
1407
+ self ._formatter .set_axis (ax )
1411
1408
1412
1409
def get_offset (self ):
1413
- if hasattr (self .formatter , 'get_axis' ):
1414
- return self .formatter .get_offset ()
1410
+ if hasattr (self ._formatter , 'get_axis' ):
1411
+ return self ._formatter .get_offset ()
1415
1412
return super (LinearScaleFormatter , self ).get_offset ()
1416
1413
1417
1414
def set_locs (self , locs ):
1418
- if hasattr (self .formatter , 'set_locs' ):
1419
- self .formatter .set_locs ([self .transform (x ) for x in locs ])
1415
+ if hasattr (self ._formatter , 'set_locs' ):
1416
+ self ._formatter .set_locs ([self .transform (x ) for x in locs ])
1420
1417
1421
1418
def fix_minus (self , s ):
1422
- if hasattr (self .formatter , 'fix_minus' ):
1423
- return self .formatter .fix_minus (s )
1419
+ if hasattr (self ._formatter , 'fix_minus' ):
1420
+ return self ._formatter .fix_minus (s )
1424
1421
return super (LinearScaleFormatter , self ).fix_minus (s )
1425
1422
1426
1423
0 commit comments