127
127
and to make the format as compact as possible while still having complete
128
128
date information. This is most useful when used with the `AutoDateLocator`.
129
129
130
- * `DateFormatter`: use `strftime` format strings.
130
+ * `DateFormatter`: use `~datetime.datetime. strftime` format strings.
131
131
132
132
* `IndexDateFormatter`: date plots with implicit *x* indexing.
133
133
"""
@@ -568,7 +568,8 @@ def drange(dstart, dend, delta):
568
568
569
569
class DateFormatter (ticker .Formatter ):
570
570
"""
571
- Format a tick (in seconds since the epoch) with a `strftime` format string.
571
+ Format a tick (in days since the epoch) with a
572
+ `~datetime.datetime.strftime` format string.
572
573
"""
573
574
574
575
illegal_s = re .compile (r"((^|[^%])(%%)*%s)" )
@@ -578,8 +579,9 @@ def __init__(self, fmt, tz=None):
578
579
Parameters
579
580
----------
580
581
fmt : str
581
- `strftime` format string
582
- tz : `tzinfo`
582
+ `~datetime.datetime.strftime` format string
583
+ tz : `tzinfo`, default: :rc:`timezone`
584
+ Ticks timezone.
583
585
"""
584
586
if tz is None :
585
587
tz = _get_rc_timezone ()
@@ -599,14 +601,12 @@ def set_tzinfo(self, tz):
599
601
600
602
601
603
class IndexDateFormatter (ticker .Formatter ):
602
- """
603
- Use with :class:`~matplotlib.ticker.IndexLocator` to cycle format
604
- strings by index.
605
- """
604
+ """Use with `.IndexLocator` to cycle format strings by index."""
605
+
606
606
def __init__ (self , t , fmt , tz = None ):
607
607
"""
608
608
*t* is a sequence of dates (floating point days). *fmt* is a
609
- :func:` strftime` format string.
609
+ `~datetime.datetime. strftime` format string.
610
610
"""
611
611
if tz is None :
612
612
tz = _get_rc_timezone ()
@@ -626,8 +626,7 @@ class ConciseDateFormatter(ticker.Formatter):
626
626
"""
627
627
This class attempts to figure out the best format to use for the
628
628
date, and to make it as compact as possible, but still be complete. This is
629
- most useful when used with the :class:`AutoDateLocator`::
630
-
629
+ most useful when used with the `AutoDateLocator`::
631
630
632
631
>>> locator = AutoDateLocator()
633
632
>>> formatter = ConciseDateFormatter(locator)
@@ -824,7 +823,7 @@ def format_data_short(self, value):
824
823
class AutoDateFormatter (ticker .Formatter ):
825
824
"""
826
825
This class attempts to figure out the best format to use. This is
827
- most useful when used with the :class: `AutoDateLocator`.
826
+ most useful when used with the `AutoDateLocator`.
828
827
829
828
The AutoDateFormatter has a scale dictionary that maps the scale
830
829
of the tick (the distance in days between one major tick) and a
@@ -850,10 +849,9 @@ class AutoDateFormatter(ticker.Formatter):
850
849
>>> formatter = AutoDateFormatter(locator)
851
850
>>> formatter.scaled[1/(24.*60.)] = '%M:%S' # only show min and sec
852
851
853
- A custom :class:`~matplotlib.ticker.FuncFormatter` can also be used.
854
- The following example shows how to use a custom format function to strip
855
- trailing zeros from decimal seconds and adds the date to the first
856
- ticklabel::
852
+ A custom `.FuncFormatter` can also be used. The following example shows
853
+ how to use a custom format function to strip trailing zeros from decimal
854
+ seconds and adds the date to the first ticklabel::
857
855
858
856
>>> def my_format_function(x, pos=None):
859
857
... x = matplotlib.dates.num2date(x)
@@ -1223,57 +1221,62 @@ def autoscale(self):
1223
1221
1224
1222
class AutoDateLocator (DateLocator ):
1225
1223
"""
1226
- On autoscale, this class picks the best
1227
- :class:`DateLocator` to set the view limits and the tick
1228
- locations.
1229
- """
1230
- def __init__ (self , tz = None , minticks = 5 , maxticks = None ,
1231
- interval_multiples = True ):
1232
- """
1233
- *minticks* is the minimum number of ticks desired, which is used to
1234
- select the type of ticking (yearly, monthly, etc.).
1224
+ On autoscale, this class picks the best `DateLocator` to set the view
1225
+ limits and the tick locations.
1235
1226
1236
- *maxticks* is the maximum number of ticks desired, which controls
1237
- any interval between ticks (ticking every other, every 3, etc.).
1238
- For really fine-grained control, this can be a dictionary mapping
1239
- individual rrule frequency constants (YEARLY, MONTHLY, etc.)
1240
- to their own maximum number of ticks. This can be used to keep
1241
- the number of ticks appropriate to the format chosen in
1242
- :class:`AutoDateFormatter`. Any frequency not specified in this
1243
- dictionary is given a default value.
1244
-
1245
- *tz* is a :class:`tzinfo` instance.
1246
-
1247
- *interval_multiples* is a boolean that indicates whether ticks
1248
- should be chosen to be multiple of the interval. This will lock
1249
- ticks to 'nicer' locations. For example, this will force the
1250
- ticks to be at hours 0, 6, 12, 18 when hourly ticking is done at
1251
- 6 hour intervals.
1252
-
1253
- The AutoDateLocator has an interval dictionary that maps the
1254
- frequency of the tick (a constant from dateutil.rrule) and a
1255
- multiple allowed for that ticking. The default looks like this::
1256
-
1257
- self.intervald = {
1258
- YEARLY : [1, 2, 4, 5, 10, 20, 40, 50, 100, 200, 400, 500,
1259
- 1000, 2000, 4000, 5000, 10000],
1260
- MONTHLY : [1, 2, 3, 4, 6],
1261
- DAILY : [1, 2, 3, 7, 14],
1262
- HOURLY : [1, 2, 3, 4, 6, 12],
1263
- MINUTELY: [1, 5, 10, 15, 30],
1264
- SECONDLY: [1, 5, 10, 15, 30],
1265
- MICROSECONDLY: [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000,
1266
- 5000, 10000, 20000, 50000, 100000, 200000, 500000,
1267
- 1000000],
1227
+ Attributes
1228
+ ----------
1229
+ intervald : dict
1230
+
1231
+ Mapping of tick frequencies (a constant from dateutil.rrule) to
1232
+ multiples allowed for that ticking. The default looks like this::
1233
+
1234
+ self.intervald = {
1235
+ YEARLY : [1, 2, 4, 5, 10, 20, 40, 50, 100, 200, 400, 500,
1236
+ 1000, 2000, 4000, 5000, 10000],
1237
+ MONTHLY : [1, 2, 3, 4, 6],
1238
+ DAILY : [1, 2, 3, 7, 14],
1239
+ HOURLY : [1, 2, 3, 4, 6, 12],
1240
+ MINUTELY: [1, 5, 10, 15, 30],
1241
+ SECONDLY: [1, 5, 10, 15, 30],
1242
+ MICROSECONDLY: [1, 2, 5, 10, 20, 50, 100, 200, 500,
1243
+ 1000, 2000, 5000, 10000, 20000, 50000,
1244
+ 100000, 200000, 500000, 1000000],
1268
1245
}
1269
1246
1270
1247
The interval is used to specify multiples that are appropriate for
1271
1248
the frequency of ticking. For instance, every 7 days is sensible
1272
1249
for daily ticks, but for minutes/seconds, 15 or 30 make sense.
1273
1250
You can customize this dictionary by doing::
1274
1251
1275
- locator = AutoDateLocator()
1276
- locator.intervald[HOURLY] = [3] # only show every 3 hours
1252
+ locator = AutoDateLocator()
1253
+ locator.intervald[HOURLY] = [3] # only show every 3 hours
1254
+ """
1255
+
1256
+ def __init__ (self , tz = None , minticks = 5 , maxticks = None ,
1257
+ interval_multiples = True ):
1258
+ """
1259
+ Parameters
1260
+ ----------
1261
+ tz : `tzinfo`
1262
+ Ticks timezone.
1263
+ minticks : int
1264
+ The minimum number of ticks desired; controls whether ticks occur
1265
+ yearly, monthly, etc.
1266
+ maxticks : int
1267
+ The maximum number of ticks desired; controls the interval between
1268
+ ticks (ticking every other, every 3, etc.). For fine-grained
1269
+ control, this can be a dictionary mapping individual rrule
1270
+ frequency constants (YEARLY, MONTHLY, etc.) to their own maximum
1271
+ number of ticks. This can be used to keep the number of ticks
1272
+ appropriate to the format chosen in `AutoDateFormatter`. Any
1273
+ frequency not specified in this dictionary is given a default
1274
+ value.
1275
+ interval_multiples : bool, default: True
1276
+ Whether ticks should be chosen to be multiple of the interval,
1277
+ locking them to 'nicer' locations. For example, this will force
1278
+ the ticks to be at hours 0, 6, 12, 18 when hourly ticking is done
1279
+ at 6 hour intervals.
1277
1280
"""
1278
1281
DateLocator .__init__ (self , tz )
1279
1282
self ._locator = YearLocator (tz = tz )
@@ -1866,17 +1869,16 @@ def weeks(w):
1866
1869
1867
1870
class DateConverter (units .ConversionInterface ):
1868
1871
"""
1869
- Converter for datetime.date and datetime.datetime data,
1870
- or for date/time data represented as it would be converted
1871
- by :func:`date2num`.
1872
+ Converter for `datetime.date` and `datetime.datetime` data, or for
1873
+ date/time data represented as it would be converted by `date2num`.
1872
1874
1873
1875
The 'unit' tag for such data is None or a tzinfo instance.
1874
1876
"""
1875
1877
1876
1878
@staticmethod
1877
1879
def axisinfo (unit , axis ):
1878
1880
"""
1879
- Return the :class: `~matplotlib.units.AxisInfo` for *unit*.
1881
+ Return the `~matplotlib.units.AxisInfo` for *unit*.
1880
1882
1881
1883
*unit* is a tzinfo instance or None.
1882
1884
The *axis* argument is required but not used.
@@ -1894,8 +1896,8 @@ def axisinfo(unit, axis):
1894
1896
@staticmethod
1895
1897
def convert (value , unit , axis ):
1896
1898
"""
1897
- If *value* is not already a number or sequence of numbers,
1898
- convert it with :func: `date2num`.
1899
+ If *value* is not already a number or sequence of numbers, convert it
1900
+ with `date2num`.
1899
1901
1900
1902
The *unit* and *axis* arguments are not used.
1901
1903
"""
@@ -1922,13 +1924,7 @@ def default_units(x, axis):
1922
1924
1923
1925
1924
1926
class ConciseDateConverter (DateConverter ):
1925
- """
1926
- Converter for datetime.date and datetime.datetime data,
1927
- or for date/time data represented as it would be converted
1928
- by :func:`date2num`.
1929
-
1930
- The 'unit' tag for such data is None or a tzinfo instance.
1931
- """
1927
+ # docstring inherited
1932
1928
1933
1929
def __init__ (self , formats = None , zero_formats = None , offset_formats = None ,
1934
1930
show_offset = True ):
@@ -1939,22 +1935,15 @@ def __init__(self, formats=None, zero_formats=None, offset_formats=None,
1939
1935
super ().__init__ ()
1940
1936
1941
1937
def axisinfo (self , unit , axis ):
1942
- """
1943
- Return the :class:`~matplotlib.units.AxisInfo` for *unit*.
1944
-
1945
- *unit* is a tzinfo instance or None.
1946
- The *axis* argument is required but not used.
1947
- """
1938
+ # docstring inherited
1948
1939
tz = unit
1949
-
1950
1940
majloc = AutoDateLocator (tz = tz )
1951
1941
majfmt = ConciseDateFormatter (majloc , tz = tz , formats = self ._formats ,
1952
1942
zero_formats = self ._zero_formats ,
1953
1943
offset_formats = self ._offset_formats ,
1954
1944
show_offset = self ._show_offset )
1955
1945
datemin = datetime .date (2000 , 1 , 1 )
1956
1946
datemax = datetime .date (2010 , 1 , 1 )
1957
-
1958
1947
return units .AxisInfo (majloc = majloc , majfmt = majfmt , label = '' ,
1959
1948
default_limits = (datemin , datemax ))
1960
1949
0 commit comments