@@ -902,10 +902,6 @@ def set_locs(self, locs=None):
902
902
self ._sublabels = None
903
903
return
904
904
905
- b = self ._base
906
-
907
- vmin , vmax = self .axis .get_view_interval ()
908
-
909
905
# Handle symlog case:
910
906
linthresh = self ._linthresh
911
907
if linthresh is None :
@@ -914,6 +910,7 @@ def set_locs(self, locs=None):
914
910
except AttributeError :
915
911
pass
916
912
913
+ vmin , vmax = self .axis .get_view_interval ()
917
914
if vmin > vmax :
918
915
vmin , vmax = vmax , vmin
919
916
@@ -924,6 +921,7 @@ def set_locs(self, locs=None):
924
921
self ._sublabels = set ((1 ,)) # label powers of base
925
922
return
926
923
924
+ b = self ._base
927
925
if linthresh is not None : # symlog
928
926
# Only compute the number of decades in the logarithmic part of the
929
927
# axis
@@ -953,37 +951,38 @@ def set_locs(self, locs=None):
953
951
# Label all integer multiples of base**n.
954
952
self ._sublabels = set (np .arange (1 , b + 1 ))
955
953
954
+ def _num_to_string (self , x , vmin , vmax ):
955
+ if x > 10000 :
956
+ s = '%1.0e' % x
957
+ elif x < 1 :
958
+ s = '%1.0e' % x
959
+ else :
960
+ s = self .pprint_val (x , vmax - vmin )
961
+
956
962
def __call__ (self , x , pos = None ):
957
963
"""
958
964
Return the format for tick val `x`.
959
965
"""
960
- vmin , vmax = self .axis .get_view_interval ()
961
- vmin , vmax = mtransforms .nonsingular (vmin , vmax , expander = 0.05 )
962
- d = abs (vmax - vmin )
963
- b = self ._base
964
966
if x == 0.0 : # Symlog
965
967
return '0'
968
+
966
969
sign = np .sign (x )
967
970
x = abs (x )
971
+ b = self ._base
968
972
# only label the decades
969
973
fx = math .log (x ) / math .log (b )
970
974
is_x_decade = is_close_to_int (fx )
971
975
exponent = np .round (fx ) if is_x_decade else np .floor (fx )
972
976
coeff = np .round (x / b ** exponent )
977
+
973
978
if self .labelOnlyBase and not is_x_decade :
974
979
return ''
975
980
if self ._sublabels is not None and coeff not in self ._sublabels :
976
981
return ''
977
982
978
- if x > 10000 :
979
- s = '%1.0e' % x
980
- elif x < 1 :
981
- s = '%1.0e' % x
982
- else :
983
- s = self .pprint_val (x , d )
984
- if sign == - 1 :
985
- s = '-%s' % s
986
-
983
+ vmin , vmax = self .axis .get_view_interval ()
984
+ vmin , vmax = mtransforms .nonsingular (vmin , vmax , expander = 0.05 )
985
+ s = self ._num_to_string (x , vmin , vmax )
987
986
return self .fix_minus (s )
988
987
989
988
def format_data (self , value ):
@@ -1036,41 +1035,16 @@ class LogFormatterExponent(LogFormatter):
1036
1035
"""
1037
1036
Format values for log axis using ``exponent = log_base(value)``.
1038
1037
"""
1039
- def __call__ (self , x , pos = None ):
1040
- """
1041
- Return the format for tick value `x`.
1042
- """
1043
- vmin , vmax = self .axis .get_view_interval ()
1044
- vmin , vmax = mtransforms .nonsingular (vmin , vmax , expander = 0.05 )
1045
- d = abs (vmax - vmin )
1046
- b = self ._base
1047
- if x == 0 :
1048
- return '0'
1049
- sign = np .sign (x )
1050
- x = abs (x )
1051
- # only label the decades
1052
- fx = math .log (x ) / math .log (b )
1053
-
1054
- is_x_decade = is_close_to_int (fx )
1055
- exponent = np .round (fx ) if is_x_decade else np .floor (fx )
1056
- coeff = np .round (x / b ** exponent )
1057
-
1058
- if self .labelOnlyBase and not is_x_decade :
1059
- return ''
1060
- if self ._sublabels is not None and coeff not in self ._sublabels :
1061
- return ''
1062
-
1038
+ def _num_to_string (self , x , vmin , vmax ):
1039
+ fx = math .log (x ) / math .log (self ._base )
1063
1040
if abs (fx ) > 10000 :
1064
1041
s = '%1.0g' % fx
1065
1042
elif abs (fx ) < 1 :
1066
1043
s = '%1.0g' % fx
1067
1044
else :
1068
- fd = math .log (abs ( d )) / math .log (b )
1045
+ fd = math .log (vmax - vmin ) / math .log (self . _base )
1069
1046
s = self .pprint_val (fx , fd )
1070
- if sign == - 1 :
1071
- s = '-%s' % s
1072
-
1073
- return self .fix_minus (s )
1047
+ return s
1074
1048
1075
1049
1076
1050
class LogFormatterMathtext (LogFormatter ):
@@ -1092,35 +1066,34 @@ def __call__(self, x, pos=None):
1092
1066
1093
1067
The position `pos` is ignored.
1094
1068
"""
1095
- b = self ._base
1096
1069
usetex = rcParams ['text.usetex' ]
1097
-
1098
- # only label the decades
1099
- if x == 0 :
1070
+ if x == 0 : # Symlog
1100
1071
if usetex :
1101
1072
return '$0$'
1102
1073
else :
1103
1074
return '$%s$' % _mathdefault ('0' )
1104
1075
1105
1076
sign_string = '-' if x < 0 else ''
1106
1077
x = abs (x )
1078
+ b = self ._base
1107
1079
1080
+ # only label the decades
1108
1081
fx = math .log (x ) / math .log (b )
1109
1082
is_x_decade = is_close_to_int (fx )
1110
1083
exponent = np .round (fx ) if is_x_decade else np .floor (fx )
1111
1084
coeff = np .round (x / b ** exponent )
1112
1085
1086
+ if self .labelOnlyBase and not is_x_decade :
1087
+ return ''
1088
+ if self ._sublabels is not None and coeff not in self ._sublabels :
1089
+ return ''
1090
+
1113
1091
# use string formatting of the base if it is not an integer
1114
1092
if b % 1 == 0.0 :
1115
1093
base = '%d' % b
1116
1094
else :
1117
1095
base = '%s' % b
1118
1096
1119
- if self .labelOnlyBase and not is_x_decade :
1120
- return ''
1121
- if self ._sublabels is not None and coeff not in self ._sublabels :
1122
- return ''
1123
-
1124
1097
if not is_x_decade :
1125
1098
return self ._non_decade_format (sign_string , base , fx , usetex )
1126
1099
else :
0 commit comments