@@ -377,8 +377,8 @@ def __call__(self, x, pos=None):
377
377
return self .pprint_val (x , d )
378
378
379
379
def pprint_val (self , x , d ):
380
- #if the number is not too big and it's an int, format it as an
381
- #int
380
+ # if the number is not too big and it's an int, format it as an
381
+ # int
382
382
if abs (x ) < 1e4 and x == int (x ):
383
383
return '%d' % x
384
384
@@ -395,7 +395,7 @@ def pprint_val(self, x, d):
395
395
else :
396
396
fmt = '%1.3f'
397
397
s = fmt % x
398
- #print d, x, fmt, s
398
+ # print d, x, fmt, s
399
399
tup = s .split ('e' )
400
400
if len (tup ) == 2 :
401
401
mantissa = tup [0 ].rstrip ('0' ).rstrip ('.' )
@@ -417,10 +417,7 @@ class ScalarFormatter(Formatter):
417
417
axes.formatter.limits rc parameter.
418
418
419
419
"""
420
- mode = {'offset' :0 ,
421
- 'scaling' :1 ,
422
- 'none' :2 ,
423
- }
420
+ mode = {'offset' : 0 , 'scaling' : 1 , 'none' : 2 , }
424
421
_currentMode = 2
425
422
426
423
def __init__ (self , useOffset = None , useMathText = None , useLocale = None ):
@@ -430,9 +427,9 @@ def __init__(self, useOffset=None, useMathText=None, useLocale=None):
430
427
431
428
self .set_useOffset (False )
432
429
self .set_useScalingFactor (False )
433
- if rcParams ['axes.formatter.useoffset' ] == True :
434
- self ._currentMode = self .mode ['offset' ]
435
- self ._currentMode = self .mode ['none' ]
430
+ if rcParams ['axes.formatter.useoffset' ] is True :
431
+ self ._currentMode = self .mode ['offset' ]
432
+ self ._currentMode = self .mode ['none' ]
436
433
437
434
self ._usetex = rcParams ['text.usetex' ]
438
435
if useMathText is None :
@@ -450,73 +447,73 @@ def __init__(self, useOffset=None, useMathText=None, useLocale=None):
450
447
def get_useScalingFactor (self ):
451
448
return self ._currentMode == self .mode ['scaling' ]
452
449
453
- def set_useScalingFactor (self ,val ):
450
+ def set_useScalingFactor (self , val ):
454
451
"""
455
- Control and set the scaling factor. Disabling this returns the
452
+ Control and set the scaling factor. Disabling this returns the
456
453
formatter to its default behavior, e.g. it will try to find
457
454
an appropriate scaling/offset if enabled.
458
- Note that either offset or scaling can be used. Therefore,
455
+ Note that either offset or scaling can be used. Therefore,
459
456
this automatically turns off offset
460
457
461
458
Parameters
462
459
----------
463
460
val : (True|False|numeric)
464
461
Enable, disable, or sets and enables the use of scaling factor
465
- in the axis.
462
+ in the axis.
466
463
467
464
Returns
468
465
-------
469
466
NONE
470
467
"""
471
468
472
469
if val in [True , False ]:
473
- self .orderOfMagnitude = math .log10 (1 )
474
- self ._currentMode = self .mode ['scaling' ]
475
- if val == False :
476
- self ._currentMode = self .mode ['none' ]
477
- elif isinstance (val ,numbers .Number ):
478
- self ._currentMode = self .mode ['scaling' ]
479
- self .orderOfMagnitude = .5 * math .log10 (val * val )
470
+ self .orderOfMagnitude = math .log10 (1 )
471
+ self ._currentMode = self .mode ['scaling' ]
472
+ if val is False :
473
+ self ._currentMode = self .mode ['none' ]
474
+ elif isinstance (val , numbers .Number ):
475
+ self ._currentMode = self .mode ['scaling' ]
476
+ self .orderOfMagnitude = .5 * math .log10 (val * val )
480
477
else :
481
478
raise ValueError ("'val' must be a number or a boolean" )
482
479
483
- useScalingFactor = property (fget = get_useScalingFactor , fset = set_useScalingFactor )
480
+ useScalingFactor = property (fget = get_useScalingFactor ,
481
+ fset = set_useScalingFactor )
484
482
485
483
def get_useOffset (self ):
486
484
return self ._currentMode == self .mode ['offset' ]
487
485
488
486
def set_useOffset (self , val ):
489
487
"""
490
- Control and set the offset. Disabling this returns the
488
+ Control and set the offset. Disabling this returns the
491
489
formatter to its default behavior, e.g. it will try to find
492
490
an appropriate scaling/offset if enabled.
493
- Note that either offset or scaling can be used. Therefore,
491
+ Note that either offset or scaling can be used. Therefore,
494
492
this automatically turns off scaling
495
493
496
494
Parameters
497
495
----------
498
496
val : (True|False|numeric)
499
497
Enable, disable, or sets and enables the use of an offset
500
- in the axis.
498
+ in the axis.
501
499
502
500
Returns
503
501
-------
504
502
NONE
505
503
"""
506
504
if val in [True , False ]:
507
505
self .offsetval = 0
508
- self ._currentMode = self .mode ['offset' ]
509
- if val == False :
510
- self ._currentMode = self .mode ['none' ]
511
- elif isinstance (val ,numbers .Number ):
512
- self ._currentMode = self .mode ['offset' ]
506
+ self ._currentMode = self .mode ['offset' ]
507
+ if val is False :
508
+ self ._currentMode = self .mode ['none' ]
509
+ elif isinstance (val , numbers .Number ):
510
+ self ._currentMode = self .mode ['offset' ]
513
511
self .offsetval = val
514
512
else :
515
513
raise ValueError ("'val' must be a number or a boolean" )
516
514
517
515
useOffset = property (fget = get_useOffset , fset = set_useOffset )
518
516
519
-
520
517
def get_useLocale (self ):
521
518
return self ._useLocale
522
519
@@ -545,13 +542,13 @@ def __call__(self, x, pos=None):
545
542
546
543
def set_scientific (self , b ):
547
544
"""
548
- Enable/disable scientific notation
545
+ Enable/disable scientific notation
549
546
see also :meth:`set_powerlimits`
550
547
551
548
Parameters
552
549
----------
553
550
b : (True|False)
554
- Enable, disable scientific notation
551
+ Enable, disable scientific notation
555
552
556
553
Returns
557
554
-------
@@ -597,12 +594,11 @@ def format_data(self, value):
597
594
s = self ._formatSciNotation (s )
598
595
return self .fix_minus (s )
599
596
600
-
601
- def set_offset_string (self ,s ):
597
+ def set_offset_string (self , value ):
602
598
"""
603
599
Set the string which typically contains the offset
604
- or the scaling factor which is to be displayed on the axis.
605
- Set this to None to allow the string set by offset or scaling
600
+ or the scaling factor which is to be displayed on the axis.
601
+ Set this to None to allow the string set by offset or scaling
606
602
algorithm.
607
603
608
604
Parameters
@@ -613,13 +609,13 @@ def set_offset_string(self,s):
613
609
-------
614
610
None
615
611
"""
616
- self ._offsetString = s
612
+ self ._offsetString = value
617
613
618
614
def get_offset (self ):
619
615
"""
620
616
Returns a string with the offset(or scientific notation)/scaling
621
617
factor which is properly formatted. This is used as additional text
622
- next to the ticks, either determined by offset/scaling or set by the
618
+ next to the ticks, either determined by offset/scaling or set by the
623
619
user
624
620
625
621
Parameters
@@ -630,29 +626,30 @@ def get_offset(self):
630
626
-------
631
627
:string
632
628
"""
633
- #String has been set manually, so just return that
634
- if self ._offsetString != None :
629
+ # String has been set manually, so just return that
630
+ if self ._offsetString is not None :
635
631
return self ._offsetString
636
632
637
633
if len (self .locs ) == 0 :
638
634
return ''
639
635
s = ''
640
636
offsetStr = ''
641
637
sciNotStr = ''
642
- if self ._currentMode == self .mode ['offset' ]:
638
+ if self ._currentMode == self .mode ['offset' ]:
643
639
if self ._currentMode == self .mode ['offset' ]:
644
640
offsetStr = self .format_data (self .offsetval )
645
641
if self .offsetval > 0 :
646
642
offsetStr = ' +' + offsetStr
647
- elif self ._currentMode == self .mode ['scaling' ]:
643
+ elif self ._currentMode == self .mode ['scaling' ]:
648
644
if self .orderOfMagnitude :
649
645
if self ._usetex or self ._useMathText :
650
646
sciNotStr = self .format_data (10 ** self .orderOfMagnitude )
651
647
else :
652
- #sciNotStr = '%g' % 10 **self.orderOfMagnitude
653
- sciNotStr = '\u22C5 ' + self .format_data (10 ** self .orderOfMagnitude )
648
+ # sciNotStr = '%g' % 10 **self.orderOfMagnitude
649
+ sciNotStr = ('\u22C5 ' + self .format_data (
650
+ 10 ** self .orderOfMagnitude ))
654
651
655
- #Do final formatting
652
+ # Do final formatting
656
653
if self ._useMathText :
657
654
if sciNotStr != '' :
658
655
sciNotStr = r'\times%s' % _mathdefault (sciNotStr )
@@ -679,10 +676,10 @@ def set_locs(self, locs):
679
676
self ._set_format (vmin , vmax )
680
677
681
678
def _set_offset (self , range ):
682
- #Determine if an offset is needed and if so, set it.
683
- #This is only needed when scaling/offset hasn't been set by the user
679
+ # Determine if an offset is needed and if so, set it.
680
+ # This is only needed when scaling/offset hasn't been set by the user
684
681
if self ._currentMode != self .mode ['none' ]:
685
- return
682
+ return
686
683
687
684
# offset of 20,001 is 20,000, for example
688
685
locs = self .locs
@@ -707,13 +704,12 @@ def _set_offset(self, range):
707
704
else :
708
705
self .set_useOffset (False )
709
706
710
-
711
707
def _set_orderOfMagnitude (self , range ):
712
708
# If the user has set scale/offset, their input is used
713
709
# if scientific notation is to be used, find the appropriate exponent
714
710
# if using an numerical offset, find the exponent after applying the
715
- if self ._currentMode != self .mode ['none' ] or self ._scientific == False :
716
- #User specified or unwanted
711
+ if self ._currentMode != self .mode ['none' ] or self ._scientific is False :
712
+ # User specified or unwanted
717
713
return
718
714
719
715
locs = np .absolute (self .locs )
@@ -730,10 +726,10 @@ def _set_orderOfMagnitude(self, range):
730
726
oom = math .floor (math .log10 (val ))
731
727
if oom <= self ._powerlimits [0 ]:
732
728
self .orderOfMagnitude = oom
733
- self ._currentMode = self .mode ['scaling' ]
729
+ self ._currentMode = self .mode ['scaling' ]
734
730
elif oom >= self ._powerlimits [1 ]:
735
731
self .orderOfMagnitude = oom
736
- self ._currentMode = self .mode ['scaling' ]
732
+ self ._currentMode = self .mode ['scaling' ]
737
733
else :
738
734
self .orderOfMagnitude = 0
739
735
@@ -744,7 +740,8 @@ def _set_format(self, vmin, vmax):
744
740
_locs = list (self .locs ) + [vmin , vmax ]
745
741
else :
746
742
_locs = self .locs
747
- locs = (np .asarray (_locs ) - self .offsetval ) / 10. ** self .orderOfMagnitude
743
+ locs = ((np .asarray (_locs ) - self .offsetval ) /
744
+ 10. ** self .orderOfMagnitude )
748
745
loc_range = np .ptp (locs )
749
746
# Curvilinear coordinates can yield two identical points.
750
747
if loc_range == 0 :
@@ -773,8 +770,8 @@ def _set_format(self, vmin, vmax):
773
770
self .format = '$%s$' % _mathdefault (self .format )
774
771
775
772
def pprint_val (self , x ):
776
- #Decide if we are doing offset, scale, or none
777
- if self ._currentMode == self .mode ['offset' ] :
773
+ # Decide if we are doing offset, scale, or none
774
+ if self ._currentMode == self .mode ['offset' ]:
778
775
xp = x - self .offsetval
779
776
elif self ._currentMode == self .mode ['scaling' ]:
780
777
xp = x / (10. ** self .orderOfMagnitude )
@@ -877,8 +874,8 @@ def format_data_short(self, value):
877
874
return '%-12g' % value
878
875
879
876
def pprint_val (self , x , d ):
880
- #if the number is not too big and it's an int, format it as an
881
- #int
877
+ # if the number is not too big and it's an int, format it as an
878
+ # int
882
879
if abs (x ) < 1e4 and x == int (x ):
883
880
return '%d' % x
884
881
@@ -1025,25 +1022,10 @@ class EngFormatter(Formatter):
1025
1022
# (https://github.com/jcrocholl/pep8/issues/271)
1026
1023
1027
1024
# The SI engineering prefixes
1028
- ENG_PREFIXES = {
1029
- - 24 : "y" ,
1030
- - 21 : "z" ,
1031
- - 18 : "a" ,
1032
- - 15 : "f" ,
1033
- - 12 : "p" ,
1034
- - 9 : "n" ,
1035
- - 6 : "\u03bc " ,
1036
- - 3 : "m" ,
1037
- 0 : "" ,
1038
- 3 : "k" ,
1039
- 6 : "M" ,
1040
- 9 : "G" ,
1041
- 12 : "T" ,
1042
- 15 : "P" ,
1043
- 18 : "E" ,
1044
- 21 : "Z" ,
1045
- 24 : "Y"
1046
- }
1025
+ ENG_PREFIXES = {- 24 : "y" , - 21 : "z" , - 18 : "a" , - 15 : "f" ,
1026
+ - 12 : "p" , - 9 : "n" , - 6 : "\u03bc " , - 3 : "m" ,
1027
+ 0 : "" , 3 : "k" , 6 : "M" , 9 : "G" , 12 : "T" ,
1028
+ 15 : "P" , 18 : "E" , 21 : "Z" , 24 : "Y" }
1047
1029
1048
1030
def __init__ (self , unit = "" , places = None ):
1049
1031
self .unit = unit
@@ -1398,15 +1380,15 @@ def le(self, x):
1398
1380
'return the largest multiple of base <= x'
1399
1381
d , m = divmod (x , self ._base )
1400
1382
if closeto (m / self ._base , 1 ): # was closeto(m, self._base)
1401
- #looks like floating point error
1383
+ # looks like floating point error
1402
1384
return (d + 1 ) * self ._base
1403
1385
return d * self ._base
1404
1386
1405
1387
def gt (self , x ):
1406
1388
'return the smallest multiple of base > x'
1407
1389
d , m = divmod (x , self ._base )
1408
1390
if closeto (m / self ._base , 1 ):
1409
- #looks like floating point error
1391
+ # looks like floating point error
1410
1392
return (d + 2 ) * self ._base
1411
1393
return (d + 1 ) * self ._base
1412
1394
@@ -1605,8 +1587,9 @@ def __call__(self):
1605
1587
return self .tick_values (vmin , vmax )
1606
1588
1607
1589
def tick_values (self , vmin , vmax ):
1608
- vmin , vmax = mtransforms .nonsingular (vmin , vmax , expander = 1e-13 ,
1609
- tiny = 1e-14 )
1590
+ vmin , vmax = mtransforms .nonsingular (vmin ,
1591
+ vmax , expander = 1e-13 ,
1592
+ tiny = 1e-14 )
1610
1593
locs = self .bin_boundaries (vmin , vmax )
1611
1594
prune = self ._prune
1612
1595
if prune == 'lower' :
@@ -1624,8 +1607,9 @@ def view_limits(self, dmin, dmax):
1624
1607
dmin = - maxabs
1625
1608
dmax = maxabs
1626
1609
1627
- dmin , dmax = mtransforms .nonsingular (dmin , dmax , expander = 1e-12 ,
1628
- tiny = 1.e-13 )
1610
+ dmin , dmax = mtransforms .nonsingular (dmin ,
1611
+ dmax , expander = 1e-12 ,
1612
+ tiny = 1.e-13 )
1629
1613
1630
1614
if rcParams ['axes.autolimit_mode' ] == 'round_numbers' :
1631
1615
return np .take (self .bin_boundaries (dmin , dmax ), [0 , - 1 ])
@@ -2180,8 +2164,8 @@ def get_locator(self, d):
2180
2164
fld = math .floor (ld )
2181
2165
base = 10 ** fld
2182
2166
2183
- #if ld==fld: base = 10**(fld-1)
2184
- #else: base = 10**fld
2167
+ # if ld==fld: base = 10**(fld-1)
2168
+ # else: base = 10**fld
2185
2169
2186
2170
if d >= 5 * base :
2187
2171
ticksize = base
0 commit comments