@@ -790,6 +790,7 @@ def __init__(self, locator, tz=None, defaultfmt='%Y-%h-%d %H:%M:%S',
790
790
self ._hourfmt = '%H'
791
791
self ._minutefmt = '%M'
792
792
self ._secondfmt = '%S'
793
+ self ._microsecondfmt = '%f'
793
794
self .offset_string = 'Dates!'
794
795
self .show_offset = show_offset
795
796
@@ -813,6 +814,7 @@ def __call__(self, x, pos=None):
813
814
dayfmt = [self ._dayfmt ] * len (tickdate )
814
815
hourfmt = [self ._hourfmt + ':' + self ._minutefmt ] * len (tickdate )
815
816
secondfmt = [self ._secondfmt ] * len (tickdate )
817
+ microsecondfmt = [self ._microsecondfmt ] * len (tickdate )
816
818
817
819
# start at year....
818
820
diffed = False
@@ -876,15 +878,54 @@ def __call__(self, x, pos=None):
876
878
if remove :
877
879
for nn in range (0 , len (tickdate )):
878
880
secondfmt [nn ] = ''
881
+ else :
882
+ for nn in range (0 , len (tickdate )):
883
+ if tickdate [nn ].second == 0 :
884
+ secondfmt [nn ] = ''
879
885
880
- # remove time if zero:
886
+ # remove extra datetime.microsecond if all zero:
887
+ maxlen = 0
888
+ oldremove = remove
881
889
remove = True
882
- for nn in range (0 , len (tickdate )):
883
- if (tickdate [nn ].hour != 0 or tickdate [nn ].minute != 0 ):
884
- remove = False
890
+ if not oldremove :
891
+ for nn in range (0 , len (tickdate )):
892
+ if tickdate [nn ].microsecond != 0 :
893
+ remove = False
894
+ fullst = '%d' % tickdate [nn ].microsecond
895
+ maxlen = max (maxlen , len (fullst .rstrip ('0' )))
885
896
if remove :
886
897
for nn in range (0 , len (tickdate )):
887
- hourfmt [nn ] = ''
898
+ microsecondfmt [nn ] = ''
899
+
900
+ # remove time
901
+ if not diffed :
902
+ diffed = False
903
+ for nn in range (1 , len (tickdate )):
904
+ if (tickdate [nn ].hour == tickdate [nn - 1 ].hour
905
+ and tickdate [nn ].minute ==
906
+ tickdate [nn - 1 ].minute ):
907
+ hourfmt [nn ] = ''
908
+ else :
909
+ diffed = True
910
+ if not diffed and tickdate [0 ].second != 0 :
911
+ offset_fmt += ' ' + hourfmt [0 ]
912
+ hourfmt [0 ] = ''
913
+ else :
914
+ remove = True
915
+ for nn in range (0 , len (tickdate )):
916
+ if (tickdate [nn ].hour != 0 or tickdate [nn ].minute != 0 ):
917
+ remove = False
918
+ if remove :
919
+ for nn in range (0 , len (tickdate )):
920
+ hourfmt [nn ] = ''
921
+ else :
922
+ for nn in range (0 , len (tickdate )):
923
+ if (tickdate [nn ].hour == 0 and
924
+ tickdate [nn ].minute == 0 ):
925
+ hourfmt [nn ] = ''
926
+ monthfmt [nn ] = self ._monthfmt
927
+
928
+
888
929
889
930
ticknew = []
890
931
for nn in range (len (tickdate )):
@@ -909,7 +950,13 @@ def __call__(self, x, pos=None):
909
950
fmt += ':'
910
951
if not secondfmt [nn ] == '' :
911
952
fmt += secondfmt [nn ]
912
- ticknew += [tickdate [nn ].strftime (fmt )]
953
+ if not microsecondfmt [nn ] == '' :
954
+ fmt += '.' + microsecondfmt [nn ]
955
+
956
+ newtickla = tickdate [nn ].strftime (fmt )
957
+ if not microsecondfmt [nn ] == '' :
958
+ newtickla = newtickla [:- (6 - maxlen )]
959
+ ticknew += [newtickla ]
913
960
914
961
result = ticknew [pos ]
915
962
self ._oldticks = ticks
0 commit comments