@@ -539,8 +539,9 @@ class AutoDateFormatter(ticker.Formatter):
539539
540540 def __init__ (self , locator , tz = None , defaultfmt = '%Y-%m-%d' ):
541541 """
542- Autofmt the date labels. The default format is the one to use
543- if none of the times in scaled match
542+ Autoformat the date labels. The default format is the one to use
543+ if none of the values in ``self.scaled`` are greater than the unit
544+ returned by ``locator._get_unit()``.
544545 """
545546 self ._locator = locator
546547 self ._tz = tz
@@ -553,21 +554,24 @@ def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'):
553554 1. / (24. * 60. ): '%H:%M:%S.%f' }
554555
555556 def __call__ (self , x , pos = None ):
556- scale = float (self ._locator ._get_unit ())
557+ locator_unit_scale = float (self ._locator ._get_unit ())
557558 fmt = self .defaultfmt
558559
559- for k in sorted (self .scaled ):
560- if k >= scale :
561- fmt = self .scaled [k ]
560+ # Pick the first scale which is greater than the locator unit.
561+ for possible_scale in sorted (self .scaled ):
562+ if possible_scale >= locator_unit_scale :
563+ fmt = self .scaled [possible_scale ]
562564 break
563565
564566 if isinstance (fmt , six .string_types ):
565567 self ._formatter = DateFormatter (fmt , self ._tz )
566- return self ._formatter (x , pos )
568+ result = self ._formatter (x , pos )
567569 elif six .callable (fmt ):
568- return fmt (x , pos )
570+ result = fmt (x , pos )
569571 else :
570- raise NotImplementedError ()
572+ raise TypeError ('Unexpected type passed to {!r}.' .formatter (self ))
573+
574+ return result
571575
572576
573577class rrulewrapper :
0 commit comments