9
9
:func:`num2date` and :func:`drange` are used to facilitate easy
10
10
conversion to and from :mod:`datetime` and numeric ranges.
11
11
12
+ .. note::
13
+ Like Python's datetime, mpl uses the Gregorian calendar for
14
+ all conversions between dates and floating point numbers.
15
+ This practice is not universal, and calendar differences can
16
+ cause confusing differences between what Python and mpl
17
+ give as the number of days since 0001-01-01 and what other
18
+ software and databases yield. For example, the
19
+ `US Naval Observatory <http://www.usno.navy.mil/USNO/astronomical-applications/data-services/jul-date>`_
20
+ uses a calendar that switches from Julian to Gregorian in
21
+ October, 1582. Hence, using their calculator, the number of
22
+ days between 0001-01-01 and 2006-04-01 is 732403, whereas using
23
+ the Gregorian calendar via the datetime module we find::
24
+
25
+ In [31]:date(2006,4,1).toordinal() - date(1,1,1).toordinal()
26
+ Out[31]:732401
27
+
28
+
12
29
A wide range of specific and general purpose date tick locators and
13
30
formatters are provided in this module. See
14
31
:mod:`matplotlib.ticker` for general information on tick locators
@@ -233,8 +250,11 @@ def date2num(d):
233
250
*d* is either a :class:`datetime` instance or a sequence of datetimes.
234
251
235
252
Return value is a floating point number (or sequence of floats)
236
- which gives one plus the number of days (fraction part represents hours,
237
- minutes, seconds) since 0001-01-01 00:00:00 UTC.
253
+ which gives the number of days (fraction part represents hours,
254
+ minutes, seconds) since 0001-01-01 00:00:00 UTC, *plus* *one*.
255
+ The addition of one here is a historical artifact. Also, note
256
+ that the Gregorian calendar is assumed; this is not universal
257
+ practice. For details, see the module docstring.
238
258
"""
239
259
if not cbook .iterable (d ): return _to_ordinalf (d )
240
260
else : return np .asarray ([_to_ordinalf (val ) for val in d ])
@@ -252,9 +272,12 @@ def num2julian(n):
252
272
253
273
def num2date (x , tz = None ):
254
274
"""
255
- *x* is a float value which gives one plus the number of days
275
+ *x* is a float value which gives the number of days
256
276
(fraction part represents hours, minutes, seconds) since
257
- 0001-01-01 00:00:00 UTC.
277
+ 0001-01-01 00:00:00 UTC *plus* *one*.
278
+ The addition of one here is a historical artifact. Also, note
279
+ that the Gregorian calendar is assumed; this is not universal
280
+ practice. For details, see the module docstring.
258
281
259
282
Return value is a :class:`datetime` instance in timezone *tz* (default to
260
283
rcparams TZ value).
0 commit comments