@@ -910,7 +910,6 @@ def pprint_val(self, x, d):
910
910
s = s .rstrip ('0' ).rstrip ('.' )
911
911
return s
912
912
913
-
914
913
class LogFormatterExponent (LogFormatter ):
915
914
"""
916
915
Format values for log axis using ``exponent = log_base(value)``.
@@ -951,6 +950,14 @@ class LogFormatterMathtext(LogFormatter):
951
950
Format values for log axis using ``exponent = log_base(value)``.
952
951
"""
953
952
953
+ def _non_decade_format (self , sign_string , base , fx , usetex ):
954
+ 'Return string for non-decade locations'
955
+ if usetex :
956
+ return (r'$%s%s^{%.2f}$' ) % (sign_string , base , fx )
957
+ else :
958
+ return ('$%s$' % _mathdefault ('%s%s^{%.2f}' %
959
+ (sign_string , base , fx )))
960
+
954
961
def __call__ (self , x , pos = None ):
955
962
"""
956
963
Return the format for tick value `x`.
@@ -981,13 +988,7 @@ def __call__(self, x, pos=None):
981
988
if not is_decade and self .labelOnlyBase :
982
989
return ''
983
990
elif not is_decade :
984
- if usetex :
985
- return (r'$%s%s^{%.2f}$' ) % \
986
- (sign_string , base , fx )
987
- else :
988
- return ('$%s$' % _mathdefault (
989
- '%s%s^{%.2f}' %
990
- (sign_string , base , fx )))
991
+ return self ._non_decade_format (sign_string , base , fx , usetex )
991
992
else :
992
993
if usetex :
993
994
return (r'$%s%s^{%d}$' ) % (sign_string ,
@@ -998,6 +999,28 @@ def __call__(self, x, pos=None):
998
999
'%s%s^{%d}' %
999
1000
(sign_string , base , nearest_long (fx ))))
1000
1001
1002
+ class LogFormatterSciNotation (LogFormatterMathtext ):
1003
+ """
1004
+ Format values following scientific notation in a logarithmic axis
1005
+ """
1006
+
1007
+ def __init__ (self , base = 10.0 , labelOnlyBase = False ):
1008
+ super (LogFormatterSciNotation , self ).__init__ (base = base ,
1009
+ labelOnlyBase = labelOnlyBase )
1010
+
1011
+ def _non_decade_format (self , sign_string , base , fx , usetex ):
1012
+ 'Return string for non-decade locations'
1013
+ b = float (base )
1014
+ exponent = math .floor (fx )
1015
+ coeff = b ** fx / b ** exponent
1016
+ if is_close_to_int (coeff ):
1017
+ coeff = nearest_long (coeff )
1018
+ if usetex :
1019
+ return (r'$%g\times%s^{%d}$' ) % \
1020
+ (coeff , base , exponent )
1021
+ else :
1022
+ return (r'$\mathdefault{%g\times%s^{%d}}$' ) % \
1023
+ (coeff , base , exponent )
1001
1024
1002
1025
class LogitFormatter (Formatter ):
1003
1026
"""
@@ -1250,6 +1273,11 @@ def __call__(self):
1250
1273
# hence there is no *one* interface to call self.tick_values.
1251
1274
raise NotImplementedError ('Derived must override' )
1252
1275
1276
+ def show_tick_label (self , locs ):
1277
+ """Return boolean array on whether to show a label for the given
1278
+ locations"""
1279
+ return np .ones (np .asarray (locs ).size , dtype = np .bool )
1280
+
1253
1281
def raise_if_exceeds (self , locs ):
1254
1282
"""raise a RuntimeError if Locator attempts to create more than
1255
1283
MAXTICKS locs"""
@@ -1894,6 +1922,33 @@ def tick_values(self, vmin, vmax):
1894
1922
1895
1923
return self .raise_if_exceeds (np .asarray (ticklocs ))
1896
1924
1925
+ def show_tick_label (self , ticklocs ):
1926
+ b = self ._base
1927
+
1928
+ vmin , vmax = self .axis .get_view_interval ()
1929
+ vmin = math .log (vmin ) / math .log (b )
1930
+ vmax = math .log (vmax ) / math .log (b )
1931
+
1932
+ numdec = abs (vmax - vmin )
1933
+
1934
+ if numdec > 3 :
1935
+ sublabel = set ((1 ))
1936
+ elif numdec > 2 :
1937
+ sublabel = set ((1 , 3 ))
1938
+ elif numdec > 1 :
1939
+ sublabel = set ((1 , 2 , 5 ))
1940
+ else :
1941
+ sublabel = set ((1 , 2 , 4 , 7 ))
1942
+
1943
+ label = np .ones (ticklocs .size , dtype = np .bool )
1944
+ for i , loc in enumerate (ticklocs ):
1945
+ exponent = math .floor (math .log (abs (loc )) / math .log (b ))
1946
+ coeff = loc / b ** nearest_long (exponent )
1947
+ if nearest_long (coeff ) not in sublabel :
1948
+ label [i ] = False
1949
+
1950
+ return label
1951
+
1897
1952
def view_limits (self , vmin , vmax ):
1898
1953
'Try to choose the view limits intelligently'
1899
1954
b = self ._base
0 commit comments