@@ -812,7 +812,7 @@ def format_ticks(self, values):
812
812
# year, month, day etc.
813
813
# fmt for most ticks at this level
814
814
fmts = self .formats
815
- # format beginnings of days, months, years, etc...
815
+ # format beginnings of days, months, years, etc.
816
816
zerofmts = self .zero_formats
817
817
# offset fmt are for the offset in the upper left of the
818
818
# or lower right of the axis.
@@ -888,48 +888,48 @@ class AutoDateFormatter(ticker.Formatter):
888
888
A `.Formatter` which attempts to figure out the best format to use. This
889
889
is most useful when used with the `AutoDateLocator`.
890
890
891
- The AutoDateFormatter has a scale dictionary that maps the scale
892
- of the tick (the distance in days between one major tick) and a
893
- format string. The default looks like this ::
891
+ `. AutoDateFormatter` has a ``. scale`` dictionary that maps tick scales (the
892
+ interval in days between one major tick) to format strings; this dictionary
893
+ defaults to ::
894
894
895
895
self.scaled = {
896
896
DAYS_PER_YEAR: rcParams['date.autoformat.year'],
897
897
DAYS_PER_MONTH: rcParams['date.autoformat.month'],
898
- 1.0 : rcParams['date.autoformat.day'],
899
- 1. / HOURS_PER_DAY: rcParams['date.autoformat.hour'],
900
- 1. / ( MINUTES_PER_DAY) : rcParams['date.autoformat.minute'],
901
- 1. / ( SEC_PER_DAY) : rcParams['date.autoformat.second'],
902
- 1. / ( MUSECONDS_PER_DAY) : rcParams['date.autoformat.microsecond'],
898
+ 1: rcParams['date.autoformat.day'],
899
+ 1 / HOURS_PER_DAY: rcParams['date.autoformat.hour'],
900
+ 1 / MINUTES_PER_DAY: rcParams['date.autoformat.minute'],
901
+ 1 / SEC_PER_DAY: rcParams['date.autoformat.second'],
902
+ 1 / MUSECONDS_PER_DAY: rcParams['date.autoformat.microsecond'],
903
903
}
904
904
905
- The algorithm picks the key in the dictionary that is >= the
906
- current scale and uses that format string. You can customize this
907
- dictionary by doing ::
905
+ The formatter uses the format string corresponding to the lowest key in
906
+ the dictionary that is greater or equal to the current scale. Dictionary
907
+ entries can be customized ::
908
908
909
- >>> locator = AutoDateLocator()
910
- >>> formatter = AutoDateFormatter(locator)
911
- >>> formatter.scaled[1/(24. *60. )] = '%M:%S' # only show min and sec
912
-
913
- A custom `.FuncFormatter` can also be used. The following example shows
914
- how to use a custom format function to strip trailing zeros from decimal
915
- seconds and adds the date to the first ticklabel::
916
-
917
- >>> def my_format_function(x, pos=None):
918
- ... x = matplotlib.dates.num2date(x)
919
- ... if pos == 0:
920
- ... fmt = '%D %H:%M:%S.%f'
921
- ... else:
922
- ... fmt = '%H:%M:%S.%f'
923
- ... label = x.strftime(fmt)
924
- ... label = label.rstrip("0")
925
- ... label = label.rstrip(".")
926
- ... return label
927
- >>> from matplotlib.ticker import FuncFormatter
928
- >>> formatter.scaled[1/(24. *60. )] = FuncFormatter( my_format_function)
909
+ locator = AutoDateLocator()
910
+ formatter = AutoDateFormatter(locator)
911
+ formatter.scaled[1/(24*60)] = '%M:%S' # only show min and sec
912
+
913
+ Custom callables can also be used instead of format strings . The following
914
+ example shows how to use a custom format function to strip trailing zeros
915
+ from decimal seconds and adds the date to the first ticklabel::
916
+
917
+ def my_format_function(x, pos=None):
918
+ x = matplotlib.dates.num2date(x)
919
+ if pos == 0:
920
+ fmt = '%D %H:%M:%S.%f'
921
+ else:
922
+ fmt = '%H:%M:%S.%f'
923
+ label = x.strftime(fmt)
924
+ label = label.rstrip("0")
925
+ label = label.rstrip(".")
926
+ return label
927
+
928
+ formatter.scaled[1/(24*60)] = my_format_function
929
929
"""
930
930
931
931
# This can be improved by providing some user-level direction on
932
- # how to choose the best format (precedence, etc...)
932
+ # how to choose the best format (precedence, etc.).
933
933
934
934
# Perhaps a 'struct' that has a field for each time-type where a
935
935
# zero would indicate "don't show" and a number would indicate
0 commit comments