@@ -798,6 +798,7 @@ def __init__(self, locator, tz=None, defaultfmt='%Y-%h-%d %H:%M:%S',
798
798
self ._hourfmt = '%H'
799
799
self ._minutefmt = '%M'
800
800
self ._secondfmt = '%S'
801
+ self ._microsecondfmt = '%f'
801
802
self .offset_string = 'Dates!'
802
803
self .show_offset = show_offset
803
804
@@ -821,6 +822,7 @@ def __call__(self, x, pos=None):
821
822
dayfmt = [self ._dayfmt ] * len (tickdate )
822
823
hourfmt = [self ._hourfmt + ':' + self ._minutefmt ] * len (tickdate )
823
824
secondfmt = [self ._secondfmt ] * len (tickdate )
825
+ microsecondfmt = [self ._microsecondfmt ] * len (tickdate )
824
826
825
827
# start at year....
826
828
diffed = False
@@ -884,15 +886,54 @@ def __call__(self, x, pos=None):
884
886
if remove :
885
887
for nn in range (0 , len (tickdate )):
886
888
secondfmt [nn ] = ''
889
+ else :
890
+ for nn in range (0 , len (tickdate )):
891
+ if tickdate [nn ].second == 0 :
892
+ secondfmt [nn ] = ''
887
893
888
- # remove time if zero:
894
+ # remove extra datetime.microsecond if all zero:
895
+ maxlen = 0
896
+ oldremove = remove
889
897
remove = True
890
- for nn in range (0 , len (tickdate )):
891
- if (tickdate [nn ].hour != 0 or tickdate [nn ].minute != 0 ):
892
- remove = False
898
+ if not oldremove :
899
+ for nn in range (0 , len (tickdate )):
900
+ if tickdate [nn ].microsecond != 0 :
901
+ remove = False
902
+ fullst = '%d' % tickdate [nn ].microsecond
903
+ maxlen = max (maxlen , len (fullst .rstrip ('0' )))
893
904
if remove :
894
905
for nn in range (0 , len (tickdate )):
895
- hourfmt [nn ] = ''
906
+ microsecondfmt [nn ] = ''
907
+
908
+ # remove time
909
+ if not diffed :
910
+ diffed = False
911
+ for nn in range (1 , len (tickdate )):
912
+ if (tickdate [nn ].hour == tickdate [nn - 1 ].hour
913
+ and tickdate [nn ].minute ==
914
+ tickdate [nn - 1 ].minute ):
915
+ hourfmt [nn ] = ''
916
+ else :
917
+ diffed = True
918
+ if not diffed and tickdate [0 ].second != 0 :
919
+ offset_fmt += ' ' + hourfmt [0 ]
920
+ hourfmt [0 ] = ''
921
+ else :
922
+ remove = True
923
+ for nn in range (0 , len (tickdate )):
924
+ if (tickdate [nn ].hour != 0 or tickdate [nn ].minute != 0 ):
925
+ remove = False
926
+ if remove :
927
+ for nn in range (0 , len (tickdate )):
928
+ hourfmt [nn ] = ''
929
+ else :
930
+ for nn in range (0 , len (tickdate )):
931
+ if (tickdate [nn ].hour == 0 and
932
+ tickdate [nn ].minute == 0 ):
933
+ hourfmt [nn ] = ''
934
+ monthfmt [nn ] = self ._monthfmt
935
+
936
+
896
937
897
938
ticknew = []
898
939
for nn in range (len (tickdate )):
@@ -917,7 +958,13 @@ def __call__(self, x, pos=None):
917
958
fmt += ':'
918
959
if not secondfmt [nn ] == '' :
919
960
fmt += secondfmt [nn ]
920
- ticknew += [tickdate [nn ].strftime (fmt )]
961
+ if not microsecondfmt [nn ] == '' :
962
+ fmt += '.' + microsecondfmt [nn ]
963
+
964
+ newtickla = tickdate [nn ].strftime (fmt )
965
+ if not microsecondfmt [nn ] == '' :
966
+ newtickla = newtickla [:- (6 - maxlen )]
967
+ ticknew += [newtickla ]
921
968
922
969
result = ticknew [pos ]
923
970
self ._oldticks = ticks
0 commit comments