@@ -1017,7 +1017,7 @@ def __call__(self, x, pos=None):
1017
1017
xmin , xmax = self .axis .get_view_interval ()
1018
1018
d = abs (xmax - xmin )
1019
1019
1020
- return self .fix_minus (format_pct (x , d ))
1020
+ return self .fix_minus (self . format_pct (x , d ))
1021
1021
1022
1022
def format_pct (self , x , d ):
1023
1023
"""
@@ -1046,16 +1046,19 @@ def format_pct(self, x, d):
1046
1046
"""
1047
1047
x = self .convert_to_pct (x )
1048
1048
if self .decimals is None :
1049
- # Luckily Python's built-in `ceil` rounds to +inf, not away
1050
- # from zero. This is very important since the equation for
1051
- # `decimals` starts out as `d > 0.5 * 10**(2 - decimals)`
1052
- # and ends up with `decimals > 2 - log10(2 * d)`.
1053
- d = self .convert_to_pct (d ) # d is a difference, so this works
1054
- decimals = math .ceil(2.0 - math .log10 (2.0 * d ))
1055
- if decimals > 5 :
1056
- decimals = 5
1057
- elif decimals < 0 :
1049
+ if d <= 0 :
1058
1050
decimals = 0
1051
+ else :
1052
+ # Luckily Python's built-in `ceil` rounds to +inf, not away
1053
+ # from zero. This is very important since the equation for
1054
+ # `decimals` starts out as `d > 0.5 * 10**(2 - decimals)`
1055
+ # and ends up with `decimals > 2 - log10(2 * d)`.
1056
+ d = self .convert_to_pct (d ) # d is a difference, so this works
1057
+ decimals = math .ceil (2.0 - math .log10 (2.0 * d ))
1058
+ if decimals > 5 :
1059
+ decimals = 5
1060
+ elif decimals < 0 :
1061
+ decimals = 0
1059
1062
else :
1060
1063
decimals = self .decimals
1061
1064
s = '{x:0.{decimals}f}' .format (x = x , decimals = int (decimals ))
0 commit comments