@@ -1012,46 +1012,47 @@ def __call__(self, x, pos=None):
1012
1012
Formats the tick as a percentage with the appropriate scaling.
1013
1013
"""
1014
1014
xmin , xmax = self .axis .get_view_interval ()
1015
- d = abs (xmax - xmin )
1015
+ range = abs (xmax - xmin )
1016
1016
1017
- return self .fix_minus (self .format_pct (x , d ))
1017
+ return self .fix_minus (self .format_pct (x , range ))
1018
1018
1019
- def format_pct (self , x , d ):
1019
+ def format_pct (self , x , range ):
1020
1020
"""
1021
1021
Formats the number as a percentage number with the correct
1022
1022
number of decimals and adds the percent symbol, if any.
1023
1023
1024
1024
If `self.decimals` is `None`, the number of digits after the
1025
- decimal point is set based on the width of the domain `d` as
1026
- follows:
1027
-
1028
- +-------+----------+------------------------+
1029
- | d | decimals | sample |
1030
- +-------+----------+------------------------+
1031
- | >50 | 0 | ``x = 34.5`` => 34 % |
1032
- +-------+----------+------------------------+
1033
- | >5 | 1 | ``x = 34.5`` => 34.5% |
1034
- +-------+----------+------------------------+
1035
- | >0.5 | 2 | ``x = 34.5`` => 34.50% |
1036
- +-------+----------+------------------------+
1037
- | ... | ... | ... |
1038
- +-------+----------+------------------------+
1039
-
1040
- This method will not be very good for tiny ranges or extremely
1041
- large ranges . It assumes that the values on the chart are
1042
- percentages displayed on a reasonable scale.
1025
+ decimal point is set based on the displayed `range` of the axis
1026
+ as follows:
1027
+
1028
+ +-------- +----------+------------------------+
1029
+ | domain | decimals | sample |
1030
+ +-------- +----------+------------------------+
1031
+ | >50 | 0 | ``x = 34.5`` => 35 % |
1032
+ +-------- +----------+------------------------+
1033
+ | >5 | 1 | ``x = 34.5`` => 34.5% |
1034
+ +-------- +----------+------------------------+
1035
+ | >0.5 | 2 | ``x = 34.5`` => 34.50% |
1036
+ +-------- +----------+------------------------+
1037
+ | ... | ... | ... |
1038
+ +-------- +----------+------------------------+
1039
+
1040
+ This method will not be very good for tiny axis ranges or
1041
+ extremely large ones . It assumes that the values on the chart
1042
+ are percentages displayed on a reasonable scale.
1043
1043
"""
1044
1044
x = self .convert_to_pct (x )
1045
1045
if self .decimals is None :
1046
- d = self .convert_to_pct (d ) # d is a difference, so this works
1047
- if d <= 0 :
1046
+ # conversion works because range is a difference
1047
+ scaled_range = self .convert_to_pct (range )
1048
+ if scaled_range <= 0 :
1048
1049
decimals = 0
1049
1050
else :
1050
1051
# Luckily Python's built-in `ceil` rounds to +inf, not away
1051
1052
# from zero. This is very important since the equation for
1052
- # `decimals` starts out as `d > 0.5 * 10**(2 - decimals)`
1053
- # and ends up with `decimals > 2 - log10(2 * d )`.
1054
- decimals = math .ceil (2.0 - math .log10 (2.0 * d ))
1053
+ # `decimals` starts out as `scaled_range > 0.5 * 10**(2 - decimals)`
1054
+ # and ends up with `decimals > 2 - log10(2 * scaled_range )`.
1055
+ decimals = math .ceil (2.0 - math .log10 (2.0 * scaled_ranged ))
1055
1056
if decimals > 5 :
1056
1057
decimals = 5
1057
1058
elif decimals < 0 :
0 commit comments