@@ -738,8 +738,6 @@ def pprint_val(self, x, d):
738
738
s = s .rstrip ('0' ).rstrip ('.' )
739
739
return s
740
740
741
- SPECIAL_LOG_EXP = set ((- 1 , 0 , 1 ,))
742
-
743
741
class LogFormatterExponent (LogFormatter ):
744
742
"""
745
743
Format values for log axis; using ``exponent = log_base(value)``
@@ -777,6 +775,13 @@ class LogFormatterMathtext(LogFormatter):
777
775
Format values for log axis; using ``exponent = log_base(value)``
778
776
"""
779
777
778
+ def _non_decade_format (self , sign_string , base , fx , usetex ):
779
+ 'Return string for non-decade locations'
780
+ if usetex :
781
+ return (r'$%s%s^{%.2f}$' ) % (sign_string , base , fx )
782
+ else :
783
+ return ('$\mathdefault{%s%s^{%.2f}}$' ) % (sign_string , base , fx )
784
+
780
785
def __call__ (self , x , pos = None ):
781
786
'Return the format for tick val *x* at position *pos*'
782
787
b = self ._base
@@ -803,12 +808,7 @@ def __call__(self, x, pos=None):
803
808
if not is_decade and self .labelOnlyBase :
804
809
return ''
805
810
elif not is_decade :
806
- if usetex :
807
- return (r'$%s%s^{%.2f}$' ) % \
808
- (sign_string , base , fx )
809
- else :
810
- return ('$\mathdefault{%s%s^{%.2f}}$' ) % \
811
- (sign_string , base , fx )
811
+ return self ._non_decade_format (sign_string , base , fx , usetex )
812
812
else :
813
813
if usetex :
814
814
return (r'$%s%s^{%d}$' ) % (sign_string ,
@@ -819,78 +819,28 @@ def __call__(self, x, pos=None):
819
819
base ,
820
820
nearest_long (fx ))
821
821
822
- class LogFormatterSciNotation (LogFormatter ):
822
+ class LogFormatterSciNotation (LogFormatterMathtext ):
823
823
"""
824
824
Format values following scientific notation in a logarithmic axis
825
-
826
- Can be used for both minor and major ticks, will follow the same logic as
827
- LogLocator with autosub to show minor labels as needed
828
825
"""
829
826
830
- def __call__ (self , x , pos = None ):
831
- 'Return the format for tick val *x* at position *pos*'
832
- b = self ._base
833
- usetex = rcParams ['text.usetex' ]
834
-
835
- if x == 0 :
836
- if usetex :
837
- return '$0$'
838
- else :
839
- return '$\mathdefault{0}$'
840
-
841
- fx = math .log (abs (x )) / math .log (b )
842
- is_decade = is_close_to_int (fx )
843
- if is_decade :
844
- exponent = nearest_long (fx )
845
- coeff = 1
846
- else :
847
- exponent = math .floor (fx )
848
- coeff = x / b ** exponent
849
-
850
- sign_string = '-' if x < 0 else ''
851
-
852
- # Do not show the base if x is between 0.1 and 10
853
- if exponent in SPECIAL_LOG_EXP :
854
- if is_close_to_int (x ):
855
- if usetex :
856
- return '$%d$' % x
857
- else :
858
- return r'$\mathdefault{%d}$' % x
859
- else :
860
- if usetex :
861
- return '$%s$' % x
862
- else :
863
- return r'$\mathdefault{%s}$' % x
827
+ def __init__ (self , base = 10.0 , labelOnlyBase = False ):
828
+ super (LogFormatterSciNotation , self ).__init__ (base = base ,
829
+ labelOnlyBase = labelOnlyBase )
864
830
865
- # use string formatting of the base if it is not an integer
866
- if is_close_to_int (b ):
867
- base = '%d' % b
868
- else :
869
- base = '%s' % b
870
-
871
- # use string formatting of the coefficient if it is not an integer
831
+ def _non_decade_format (self , sign_string , base , fx , usetex ):
832
+ 'Return string for non-decade locations'
833
+ b = float (base )
834
+ exponent = math .floor (fx )
835
+ coeff = b ** fx / b ** exponent
872
836
if is_close_to_int (coeff ):
873
- coeff = '%d' % coeff
874
- else :
875
- coeff = '%s' % coeff
876
-
877
- if is_decade :
878
- if usetex :
879
- return (r'$%s%s^{%d}$' ) % (sign_string ,
880
- base ,
881
- nearest_long (fx ))
882
- else :
883
- return (r'$\mathdefault{%s%s^{%d}}$' ) % (sign_string ,
884
- base ,
885
- nearest_long (fx ))
837
+ coeff = nearest_long (coeff )
838
+ if usetex :
839
+ return (r'$%g\times%s^{%d}$' ) % \
840
+ (coeff , base , exponent )
886
841
else :
887
- if usetex :
888
- return (r'$%s\times%s^{%d}$' ) % \
889
- (coeff , base , exponent )
890
- else :
891
- return (r'$\mathdefault{%s\times%s^{%d}}$' ) % \
892
- (coeff , base , exponent )
893
-
842
+ return (r'$\mathdefault{%g\times%s^{%d}}$' ) % \
843
+ (coeff , base , exponent )
894
844
895
845
class LogitFormatter (Formatter ):
896
846
'''Probability formatter (using Math text)'''
0 commit comments