@@ -437,14 +437,28 @@ def __call__(self, x, pos=None):
437
437
The position `pos` is ignored.
438
438
"""
439
439
xmin , xmax = self .axis .get_view_interval ()
440
+ # If the number is not too big and it's an int, format it as an int.
441
+ if abs (x ) < 1e4 and x == int (x ):
442
+ return '%d' % x
440
443
d = abs (xmax - xmin )
441
- return self ._pprint_val (x , d )
444
+ fmt = ('%1.3e' if d < 1e-2 else
445
+ '%1.3f' if d <= 1 else
446
+ '%1.2f' if d <= 10 else
447
+ '%1.1f' if d <= 1e5 else
448
+ '%1.1e' )
449
+ s = fmt % x
450
+ tup = s .split ('e' )
451
+ if len (tup ) == 2 :
452
+ mantissa = tup [0 ].rstrip ('0' ).rstrip ('.' )
453
+ sign = tup [1 ][0 ].replace ('+' , '' )
454
+ exponent = tup [1 ][1 :].lstrip ('0' )
455
+ s = '%se%s%s' % (mantissa , sign , exponent )
456
+ else :
457
+ s = s .rstrip ('0' ).rstrip ('.' )
458
+ return s
442
459
443
460
@cbook .deprecated ("3.1" )
444
- def pprint_val (self , * args , ** kwargs ):
445
- return self ._pprint_val (* args , ** kwargs )
446
-
447
- def _pprint_val (self , x , d ):
461
+ def pprint_val (self , x , d ):
448
462
"""
449
463
Formats the value `x` based on the size of the axis range `d`.
450
464
"""
@@ -560,7 +574,13 @@ def __call__(self, x, pos=None):
560
574
if len (self .locs ) == 0 :
561
575
return ''
562
576
else :
563
- s = self ._pprint_val (x )
577
+ xp = (x - self .offset ) / (10. ** self .orderOfMagnitude )
578
+ if np .abs (xp ) < 1e-8 :
579
+ xp = 0
580
+ if self ._useLocale :
581
+ s = locale .format_string (self .format , (xp ,))
582
+ else :
583
+ s = self .format % xp
564
584
return self .fix_minus (s )
565
585
566
586
def set_scientific (self , b ):
@@ -767,10 +787,7 @@ def _set_format(self):
767
787
self .format = '$%s$' % _mathdefault (self .format )
768
788
769
789
@cbook .deprecated ("3.1" )
770
- def pprint_val (self , * args , ** kwargs ):
771
- return self ._pprint_val (* args , ** kwargs )
772
-
773
- def _pprint_val (self , x ):
790
+ def pprint_val (self , x ):
774
791
xp = (x - self .offset ) / (10. ** self .orderOfMagnitude )
775
792
if np .abs (xp ) < 1e-8 :
776
793
xp = 0
@@ -1019,21 +1036,12 @@ def _pprint_val(self, x, d):
1019
1036
# If the number is not too big and it's an int, format it as an int.
1020
1037
if abs (x ) < 1e4 and x == int (x ):
1021
1038
return '%d' % x
1022
-
1023
- if d < 1e-2 :
1024
- fmt = '%1.3e'
1025
- elif d < 1e-1 :
1026
- fmt = '%1.3f'
1027
- elif d > 1e5 :
1028
- fmt = '%1.1e'
1029
- elif d > 10 :
1030
- fmt = '%1.1f'
1031
- elif d > 1 :
1032
- fmt = '%1.2f'
1033
- else :
1034
- fmt = '%1.3f'
1039
+ fmt = ('%1.3e' if d < 1e-2 else
1040
+ '%1.3f' if d <= 1 else
1041
+ '%1.2f' if d <= 10 else
1042
+ '%1.1f' if d <= 1e5 else
1043
+ '%1.1e' )
1035
1044
s = fmt % x
1036
-
1037
1045
tup = s .split ('e' )
1038
1046
if len (tup ) == 2 :
1039
1047
mantissa = tup [0 ].rstrip ('0' ).rstrip ('.' )
0 commit comments