154154:class:`PercentFormatter`
155155 Format labels as a percentage
156156
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.
162159
163160:class:`LinearScaleFormatter`
164161 Wrap another formatter to display transformed values.
204201 'LogFormatterExponent' , 'LogFormatterMathtext' ,
205202 'IndexFormatter' , 'LogFormatterSciNotation' ,
206203 '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' ,
210207 'MultipleLocator' , 'MaxNLocator' , 'AutoMinorLocator' ,
211208 'SymmetricalLogLocator' , 'LogitLocator' )
212209
@@ -1335,21 +1332,21 @@ def transform(self, x):
13351332 """
13361333 Ensures that `x` is an integer.
13371334
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`.
13411338
13421339 Returns the transformed number.
13431340 """
13441341 x = int (x )
13451342 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
13471344 x = x & ((1 << bits ) - 1 )
13481345 return x
13491346
13501347 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 )
13531350
13541351
13551352class LinearScaleFormatter (Formatter ):
@@ -1360,67 +1357,67 @@ class LinearScaleFormatter(Formatter):
13601357 This formatter can use any other formatter to actually render the
13611358 ticks.
13621359
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
13741377 The instance to delegate the actual formatting of the
13751378 transformed value to. This does not have to be an instance of
13761379 ``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.
13781381 """
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 ()):
13891384 # 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
13941391
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
13981395
13991396 def transform (self , x ):
14001397 """
14011398 Transforms a value from the input scale to the output scale.
14021399 """
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
14041401
14051402 def __call__ (self , x , pos = None ):
1406- return self .formatter (self .transform (x ), pos )
1403+ return self ._formatter (self .transform (x ), pos )
14071404
14081405 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 )
14111408
14121409 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 ()
14151412 return super (LinearScaleFormatter , self ).get_offset ()
14161413
14171414 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 ])
14201417
14211418 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 )
14241421 return super (LinearScaleFormatter , self ).fix_minus (s )
14251422
14261423
0 commit comments