3
3
Matplotlib provides sophisticated date plotting capabilities, standing
4
4
on the shoulders of python :mod:`datetime`, the add-on modules
5
5
:mod:`pytz` and :mod:`dateutils`. :class:`datetime` objects are
6
- converted to floating point numbers which represent the number of days
7
- since 0001-01-01 UTC. The helper functions :func:`date2num`,
6
+ converted to floating point numbers which represent time in days
7
+ since 0001-01-01 UTC, plus 1. For example, 0001-01-01, 06:00 is
8
+ 1.25, not 0.25. The helper functions :func:`date2num`,
8
9
:func:`num2date` and :func:`drange` are used to facilitate easy
9
10
conversion to and from :mod:`datetime` and numeric ranges.
10
11
@@ -225,7 +226,7 @@ def date2num(d):
225
226
*d* is either a :class:`datetime` instance or a sequence of datetimes.
226
227
227
228
Return value is a floating point number (or sequence of floats)
228
- which gives number of days (fraction part represents hours,
229
+ which gives one plus the number of days (fraction part represents hours,
229
230
minutes, seconds) since 0001-01-01 00:00:00 UTC.
230
231
"""
231
232
if not cbook .iterable (d ): return _to_ordinalf (d )
@@ -235,17 +236,18 @@ def date2num(d):
235
236
def julian2num (j ):
236
237
'Convert a Julian date (or sequence) to a matplotlib date (or sequence).'
237
238
if cbook .iterable (j ): j = np .asarray (j )
238
- return j + 1721425 .5
239
+ return j - 1721424 .5
239
240
240
241
def num2julian (n ):
241
242
'Convert a matplotlib date (or sequence) to a Julian date (or sequence).'
242
243
if cbook .iterable (n ): n = np .asarray (n )
243
- return n - 1721425 .5
244
+ return n + 1721424 .5
244
245
245
246
def num2date (x , tz = None ):
246
247
"""
247
- *x* is a float value which gives number of days (fraction part
248
- represents hours, minutes, seconds) since 0001-01-01 00:00:00 UTC.
248
+ *x* is a float value which gives one plus the number of days
249
+ (fraction part represents hours, minutes, seconds) since
250
+ 0001-01-01 00:00:00 UTC.
249
251
250
252
Return value is a :class:`datetime` instance in timezone *tz* (default to
251
253
rcparams TZ value).
0 commit comments