From: <jr...@us...> - 2009-02-03 22:29:34
|
Revision: 6872 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6872&view=rev Author: jrevans Date: 2009-02-03 22:29:30 +0000 (Tue, 03 Feb 2009) Log Message: ----------- Fixed a bug in RRuleLocator that generated invalid datetimes when padding the axes bounds for large ranges of times or with times that are close to the boundaries of valid datetimes. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/dates.py Modified: trunk/matplotlib/lib/matplotlib/dates.py =================================================================== --- trunk/matplotlib/lib/matplotlib/dates.py 2009-02-03 19:52:02 UTC (rev 6871) +++ trunk/matplotlib/lib/matplotlib/dates.py 2009-02-03 22:29:30 UTC (rev 6872) @@ -481,7 +481,20 @@ if dmin>dmax: dmax, dmin = dmin, dmax delta = relativedelta(dmax, dmin) - self.rule.set(dtstart=dmin-delta, until=dmax+delta) + + # We need to cap at the endpoints of valid datetime + try: + start = dmin - delta + except ValueError: + start = _from_ordinalf( 1.0 ) + + try: + stop = dmax + delta + except ValueError: + # The magic number! + stop = _from_ordinalf( 3652059.9999999 ) + + self.rule.set(dtstart=start, until=stop) dates = self.rule.between(dmin, dmax, True) return date2num(dates) @@ -518,7 +531,20 @@ dmax, dmin = dmin, dmax delta = relativedelta(dmax, dmin) - self.rule.set(dtstart=dmin-delta, until=dmax+delta) + + # We need to cap at the endpoints of valid datetime + try: + start = dmin - delta + except ValueError: + start = _from_ordinalf( 1.0 ) + + try: + stop = dmax + delta + except ValueError: + # The magic number! + stop = _from_ordinalf( 3652059.9999999 ) + + self.rule.set(dtstart=start, until=stop) dmin, dmax = self.datalim_to_dt() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2009-08-20 23:15:21
|
Revision: 7512 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7512&view=rev Author: jdh2358 Date: 2009-08-20 23:15:07 +0000 (Thu, 20 Aug 2009) Log Message: ----------- make autodateformatter customizable Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/dates.py Modified: trunk/matplotlib/lib/matplotlib/dates.py =================================================================== --- trunk/matplotlib/lib/matplotlib/dates.py 2009-08-20 23:11:44 UTC (rev 7511) +++ trunk/matplotlib/lib/matplotlib/dates.py 2009-08-20 23:15:07 UTC (rev 7512) @@ -413,12 +413,15 @@ # Or more simply, perhaps just a format string for each # possibility... - def __init__(self, locator, tz=None): + def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'): """ + Autofmt the date labels. The default format is the one to use + if none of the times in scaled match """ self._locator = locator self._tz = tz - self._formatter = DateFormatter("%b %d %Y %H:%M:%D", tz) + self.defaultfmt = defaultfmt + self._formatter = DateFormatter(self.defaultfmt, tz) self.scaled = { 365.0 : '%Y', 30. : '%b %Y', @@ -432,11 +435,14 @@ keys = self.scaled.keys() keys.sort() + fmt = self.defaultfmt + for k in keys: if k>=scale: - self._formatter = DateFormatter(self.scaled[k]) + fmt = self.scaled[k] break + self._formatter = DateFormatter(fmt) return self._formatter(x, pos) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2009-08-20 23:16:19
|
Revision: 7513 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7513&view=rev Author: jdh2358 Date: 2009-08-20 23:16:11 +0000 (Thu, 20 Aug 2009) Log Message: ----------- make autodateformatter customizable Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/dates.py Modified: trunk/matplotlib/lib/matplotlib/dates.py =================================================================== --- trunk/matplotlib/lib/matplotlib/dates.py 2009-08-20 23:15:07 UTC (rev 7512) +++ trunk/matplotlib/lib/matplotlib/dates.py 2009-08-20 23:16:11 UTC (rev 7513) @@ -432,12 +432,9 @@ def __call__(self, x, pos=0): scale = float( self._locator._get_unit() ) - keys = self.scaled.keys() - keys.sort() - fmt = self.defaultfmt - for k in keys: + for k in sorted(self.scaled): if k>=scale: fmt = self.scaled[k] break This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2010-03-08 18:33:17
|
Revision: 8182 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8182&view=rev Author: efiring Date: 2010-03-08 18:33:04 +0000 (Mon, 08 Mar 2010) Log Message: ----------- dates.py: fix num2jul, jul2num; fixes bug 2963391; thanks to G. Lichtenberg Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/dates.py Modified: trunk/matplotlib/lib/matplotlib/dates.py =================================================================== --- trunk/matplotlib/lib/matplotlib/dates.py 2010-03-08 18:09:55 UTC (rev 8181) +++ trunk/matplotlib/lib/matplotlib/dates.py 2010-03-08 18:33:04 UTC (rev 8182) @@ -3,8 +3,9 @@ Matplotlib provides sophisticated date plotting capabilities, standing on the shoulders of python :mod:`datetime`, the add-on modules :mod:`pytz` and :mod:`dateutils`. :class:`datetime` objects are -converted to floating point numbers which represent the number of days -since 0001-01-01 UTC. The helper functions :func:`date2num`, +converted to floating point numbers which represent time in days +since 0001-01-01 UTC, plus 1. For example, 0001-01-01, 06:00 is +1.25, not 0.25. The helper functions :func:`date2num`, :func:`num2date` and :func:`drange` are used to facilitate easy conversion to and from :mod:`datetime` and numeric ranges. @@ -225,7 +226,7 @@ *d* is either a :class:`datetime` instance or a sequence of datetimes. Return value is a floating point number (or sequence of floats) - which gives number of days (fraction part represents hours, + which gives one plus the number of days (fraction part represents hours, minutes, seconds) since 0001-01-01 00:00:00 UTC. """ if not cbook.iterable(d): return _to_ordinalf(d) @@ -235,17 +236,18 @@ def julian2num(j): 'Convert a Julian date (or sequence) to a matplotlib date (or sequence).' if cbook.iterable(j): j = np.asarray(j) - return j + 1721425.5 + return j - 1721424.5 def num2julian(n): 'Convert a matplotlib date (or sequence) to a Julian date (or sequence).' if cbook.iterable(n): n = np.asarray(n) - return n - 1721425.5 + return n + 1721424.5 def num2date(x, tz=None): """ - *x* is a float value which gives number of days (fraction part - represents hours, minutes, seconds) since 0001-01-01 00:00:00 UTC. + *x* is a float value which gives one plus the number of days + (fraction part represents hours, minutes, seconds) since + 0001-01-01 00:00:00 UTC. Return value is a :class:`datetime` instance in timezone *tz* (default to rcparams TZ value). This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2010-06-07 23:39:31
|
Revision: 8396 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8396&view=rev Author: efiring Date: 2010-06-07 23:39:24 +0000 (Mon, 07 Jun 2010) Log Message: ----------- dates: improve documentation related to use of Gregorian calendar Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/dates.py Modified: trunk/matplotlib/lib/matplotlib/dates.py =================================================================== --- trunk/matplotlib/lib/matplotlib/dates.py 2010-06-07 20:15:11 UTC (rev 8395) +++ trunk/matplotlib/lib/matplotlib/dates.py 2010-06-07 23:39:24 UTC (rev 8396) @@ -9,6 +9,23 @@ :func:`num2date` and :func:`drange` are used to facilitate easy conversion to and from :mod:`datetime` and numeric ranges. +.. note:: + Like Python's datetime, mpl uses the Gregorian calendar for + all conversions between dates and floating point numbers. + This practice is not universal, and calendar differences can + cause confusing differences between what Python and mpl + give as the number of days since 0001-01-01 and what other + software and databases yield. For example, the + `US Naval Observatory <http://www.usno.navy.mil/USNO/astronomical-applications/data-services/jul-date>`_ + uses a calendar that switches from Julian to Gregorian in + October, 1582. Hence, using their calculator, the number of + days between 0001-01-01 and 2006-04-01 is 732403, whereas using + the Gregorian calendar via the datetime module we find:: + + In [31]:date(2006,4,1).toordinal() - date(1,1,1).toordinal() + Out[31]:732401 + + A wide range of specific and general purpose date tick locators and formatters are provided in this module. See :mod:`matplotlib.ticker` for general information on tick locators @@ -233,8 +250,11 @@ *d* is either a :class:`datetime` instance or a sequence of datetimes. Return value is a floating point number (or sequence of floats) - which gives one plus the number of days (fraction part represents hours, - minutes, seconds) since 0001-01-01 00:00:00 UTC. + which gives the number of days (fraction part represents hours, + minutes, seconds) since 0001-01-01 00:00:00 UTC, *plus* *one*. + The addition of one here is a historical artifact. Also, note + that the Gregorian calendar is assumed; this is not universal + practice. For details, see the module docstring. """ if not cbook.iterable(d): return _to_ordinalf(d) else: return np.asarray([_to_ordinalf(val) for val in d]) @@ -252,9 +272,12 @@ def num2date(x, tz=None): """ - *x* is a float value which gives one plus the number of days + *x* is a float value which gives the number of days (fraction part represents hours, minutes, seconds) since - 0001-01-01 00:00:00 UTC. + 0001-01-01 00:00:00 UTC *plus* *one*. + The addition of one here is a historical artifact. Also, note + that the Gregorian calendar is assumed; this is not universal + practice. For details, see the module docstring. Return value is a :class:`datetime` instance in timezone *tz* (default to rcparams TZ value). This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |