@@ -801,7 +801,7 @@ class LogFormatter(Formatter):
801
801
Format values for log axis.
802
802
"""
803
803
def __init__ (self , base = 10.0 , labelOnlyBase = False ,
804
- label_pruning = False ):
804
+ minor_thresholds = ( 1 , 0.4 ) ):
805
805
"""
806
806
`base` is used to locate the decade tick, which will be the only
807
807
one to be labeled if `labelOnlyBase` is ``True``.
@@ -812,15 +812,21 @@ def __init__(self, base=10.0, labelOnlyBase=False,
812
812
base of the logarithm.
813
813
814
814
labelOnlyBase : bool, optional, default: False
815
- whether to only label decades ticks.
815
+ whether label ticks only at integer multiples of base.
816
+ This is normally True for major ticks and False for
817
+ minor ticks.
816
818
817
- label_pruning : bool, optional, default: False
818
- when set to True, label on a subset of ticks.
819
+ minor_thresholds : (subset, all), optional, default: (1, 0.4)
820
+ Thresholds applied to the data range measured in powers
821
+ of the base (numbers of "decades", or 'numdec'), and
822
+ effective only when labelOnlyBase is False. Then a
823
+ subset of minor ticks will be labeled if `numdec <= subset`,
824
+ and all will be labeled if `numdec <= all`.
819
825
"""
820
826
self ._base = base + 0.0
821
827
self .labelOnlyBase = labelOnlyBase
822
- self .label_pruning = label_pruning
823
- self ._sublabels = [ 1 , ]
828
+ self .minor_thresholds = minor_thresholds
829
+ self ._sublabels = None
824
830
825
831
def base (self , base ):
826
832
"""
@@ -872,13 +878,15 @@ def set_locs(self, locs):
872
878
vmax = math .log (vmax ) / math .log (b )
873
879
numdec = abs (vmax - vmin )
874
880
875
- if numdec > 1 :
881
+ if numdec > self . minor_thresholds [ 0 ] :
876
882
# Label only bases
877
883
self ._sublabels = set ((1 ,))
878
- else :
884
+ elif numdec > self . minor_thresholds [ 1 ] :
879
885
# Add labels between bases at log-spaced coefficients
880
- c = np .logspace (0 , 1 , ( 4 - int ( numdec )) + 1 , base = b )
886
+ c = np .logspace (0 , 1 , b // 2 + 1 , base = b )[ 1 : - 1 ]
881
887
self ._sublabels = set (np .round (c ))
888
+ else :
889
+ self ._sublabels = set (np .linspace (2 , b - 1 , b - 2 ))
882
890
883
891
def __call__ (self , x , pos = None ):
884
892
"""
@@ -895,9 +903,9 @@ def __call__(self, x, pos=None):
895
903
exponent = np .round (fx ) if isDecade else np .floor (fx )
896
904
coeff = np .round (x / b ** exponent )
897
905
898
- if self .label_pruning and coeff not in self . _sublabels :
906
+ if self .labelOnlyBase and not isDecade :
899
907
return ''
900
- if not isDecade and self .labelOnlyBase :
908
+ if self . _sublabels is not None and coeff not in self ._sublabels :
901
909
return ''
902
910
903
911
if x > 10000 :
@@ -972,16 +980,17 @@ def __call__(self, x, pos=None):
972
980
if x == 0 :
973
981
return '0'
974
982
sign = np .sign (x )
983
+ x = abs (x )
975
984
# only label the decades
976
- fx = math .log (abs ( x ) ) / math .log (b )
985
+ fx = math .log (x ) / math .log (b )
977
986
978
987
isDecade = is_close_to_int (fx )
979
988
exponent = np .round (fx ) if isDecade else np .floor (fx )
980
- coeff = np .round (abs ( x ) / b ** exponent )
989
+ coeff = np .round (x / b ** exponent )
981
990
982
- if self .label_pruning and coeff not in self . _sublabels :
991
+ if self .labelOnlyBase and not isDecade :
983
992
return ''
984
- if not isDecade and self .labelOnlyBase :
993
+ if self . _sublabels is not None and coeff not in self ._sublabels :
985
994
return ''
986
995
987
996
if abs (fx ) > 10000 :
@@ -1039,9 +1048,9 @@ def __call__(self, x, pos=None):
1039
1048
else :
1040
1049
base = '%s' % b
1041
1050
1042
- if self .label_pruning and coeff not in self . _sublabels :
1051
+ if self .labelOnlyBase and not isDecade :
1043
1052
return ''
1044
- if not is_decade and self .labelOnlyBase :
1053
+ if self . _sublabels is not None and coeff not in self ._sublabels :
1045
1054
return ''
1046
1055
1047
1056
if not is_decade :
0 commit comments