Python matplotlib.dates.UTC Examples

The following are 28 code examples of matplotlib.dates.UTC(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module matplotlib.dates , or try the search function .
Example #1
Source File: test_dates.py    From twitter-stock-recommendation with MIT License 6 votes vote down vote up
def _test_date2num_dst(date_range, tz_convert):
    # Timezones
    BRUSSELS = pytz.timezone('Europe/Brussels')
    UTC = pytz.UTC

    # Create a list of timezone-aware datetime objects in UTC
    # Interval is 0b0.0000011 days, to prevent float rounding issues
    dtstart = datetime.datetime(2014, 3, 30, 0, 0, tzinfo=UTC)
    interval = datetime.timedelta(minutes=33, seconds=45)
    interval_days = 0.0234375   # 2025 / 86400 seconds
    N = 8

    dt_utc = date_range(start=dtstart, freq=interval, periods=N)
    dt_bxl = tz_convert(dt_utc, BRUSSELS)

    expected_ordinalf = [735322.0 + (i * interval_days) for i in range(N)]
    actual_ordinalf = list(mdates.date2num(dt_bxl))

    assert actual_ordinalf == expected_ordinalf 
Example #2
Source File: test_dates.py    From coffeegrindsize with MIT License 6 votes vote down vote up
def _test_date2num_dst(date_range, tz_convert):
    # Timezones
    BRUSSELS = dateutil.tz.gettz('Europe/Brussels')
    UTC = mdates.UTC

    # Create a list of timezone-aware datetime objects in UTC
    # Interval is 0b0.0000011 days, to prevent float rounding issues
    dtstart = datetime.datetime(2014, 3, 30, 0, 0, tzinfo=UTC)
    interval = datetime.timedelta(minutes=33, seconds=45)
    interval_days = 0.0234375   # 2025 / 86400 seconds
    N = 8

    dt_utc = date_range(start=dtstart, freq=interval, periods=N)
    dt_bxl = tz_convert(dt_utc, BRUSSELS)

    expected_ordinalf = [735322.0 + (i * interval_days) for i in range(N)]
    actual_ordinalf = list(mdates.date2num(dt_bxl))

    assert actual_ordinalf == expected_ordinalf 
Example #3
Source File: test_dates.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _test_date2num_dst(date_range, tz_convert):
    # Timezones
    BRUSSELS = dateutil.tz.gettz('Europe/Brussels')
    UTC = mdates.UTC

    # Create a list of timezone-aware datetime objects in UTC
    # Interval is 0b0.0000011 days, to prevent float rounding issues
    dtstart = datetime.datetime(2014, 3, 30, 0, 0, tzinfo=UTC)
    interval = datetime.timedelta(minutes=33, seconds=45)
    interval_days = 0.0234375   # 2025 / 86400 seconds
    N = 8

    dt_utc = date_range(start=dtstart, freq=interval, periods=N)
    dt_bxl = tz_convert(dt_utc, BRUSSELS)

    expected_ordinalf = [735322.0 + (i * interval_days) for i in range(N)]
    actual_ordinalf = list(mdates.date2num(dt_bxl))

    assert actual_ordinalf == expected_ordinalf 
Example #4
Source File: _converter.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def _dt_to_float_ordinal(dt):
    """
    Convert :mod:`datetime` to the Gregorian date as UTC float days,
    preserving hours, minutes, seconds and microseconds.  Return value
    is a :func:`float`.
    """
    if (isinstance(dt, (np.ndarray, Index, ABCSeries)
                   ) and is_datetime64_ns_dtype(dt)):
        base = dates.epoch2num(dt.asi8 / 1.0E9)
    else:
        base = dates.date2num(dt)
    return base


# Datetime Conversion 
Example #5
Source File: _converter.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def _dt_to_float_ordinal(dt):
    """
    Convert :mod:`datetime` to the Gregorian date as UTC float days,
    preserving hours, minutes, seconds and microseconds.  Return value
    is a :func:`float`.
    """
    if (isinstance(dt, (np.ndarray, Index, ABCSeries)
                   ) and is_datetime64_ns_dtype(dt)):
        base = dates.epoch2num(dt.asi8 / 1.0E9)
    else:
        base = dates.date2num(dt)
    return base


# Datetime Conversion 
Example #6
Source File: test_dates.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_tz_utc():
    dt = datetime.datetime(1970, 1, 1, tzinfo=mdates.UTC)
    dt.tzname() 
Example #7
Source File: test_dates.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_drange():
    """
    This test should check if drange works as expected, and if all the
    rounding errors are fixed
    """
    start = datetime.datetime(2011, 1, 1, tzinfo=mdates.UTC)
    end = datetime.datetime(2011, 1, 2, tzinfo=mdates.UTC)
    delta = datetime.timedelta(hours=1)
    # We expect 24 values in drange(start, end, delta), because drange returns
    # dates from an half open interval [start, end)
    assert len(mdates.drange(start, end, delta)) == 24

    # if end is a little bit later, we expect the range to contain one element
    # more
    end = end + datetime.timedelta(microseconds=1)
    assert len(mdates.drange(start, end, delta)) == 25

    # reset end
    end = datetime.datetime(2011, 1, 2, tzinfo=mdates.UTC)

    # and tst drange with "complicated" floats:
    # 4 hours = 1/6 day, this is an "dangerous" float
    delta = datetime.timedelta(hours=4)
    daterange = mdates.drange(start, end, delta)
    assert len(daterange) == 6
    assert mdates.num2date(daterange[-1]) == (end - delta) 
Example #8
Source File: test_dates.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_RRuleLocator_dayrange():
    loc = mdates.DayLocator()
    x1 = datetime.datetime(year=1, month=1, day=1, tzinfo=pytz.UTC)
    y1 = datetime.datetime(year=1, month=1, day=16, tzinfo=pytz.UTC)
    loc.tick_values(x1, y1)
    # On success, no overflow error shall be thrown 
Example #9
Source File: _converter.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def _dt_to_float_ordinal(dt):
    """
    Convert :mod:`datetime` to the Gregorian date as UTC float days,
    preserving hours, minutes, seconds and microseconds.  Return value
    is a :func:`float`.
    """
    if (isinstance(dt, (np.ndarray, Index, ABCSeries)
                   ) and is_datetime64_ns_dtype(dt)):
        base = dates.epoch2num(dt.asi8 / 1.0E9)
    else:
        base = dates.date2num(dt)
    return base


# Datetime Conversion 
Example #10
Source File: test_dates.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_tz_utc():
    dt = datetime.datetime(1970, 1, 1, tzinfo=mdates.UTC)
    dt.tzname() 
Example #11
Source File: test_dates.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_drange():
    """
    This test should check if drange works as expected, and if all the
    rounding errors are fixed
    """
    start = datetime.datetime(2011, 1, 1, tzinfo=mdates.UTC)
    end = datetime.datetime(2011, 1, 2, tzinfo=mdates.UTC)
    delta = datetime.timedelta(hours=1)
    # We expect 24 values in drange(start, end, delta), because drange returns
    # dates from an half open interval [start, end)
    assert len(mdates.drange(start, end, delta)) == 24

    # if end is a little bit later, we expect the range to contain one element
    # more
    end = end + datetime.timedelta(microseconds=1)
    assert len(mdates.drange(start, end, delta)) == 25

    # reset end
    end = datetime.datetime(2011, 1, 2, tzinfo=mdates.UTC)

    # and tst drange with "complicated" floats:
    # 4 hours = 1/6 day, this is an "dangerous" float
    delta = datetime.timedelta(hours=4)
    daterange = mdates.drange(start, end, delta)
    assert len(daterange) == 6
    assert mdates.num2date(daterange[-1]) == (end - delta) 
Example #12
Source File: test_dates.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_RRuleLocator_dayrange():
    loc = mdates.DayLocator()
    x1 = datetime.datetime(year=1, month=1, day=1, tzinfo=mdates.UTC)
    y1 = datetime.datetime(year=1, month=1, day=16, tzinfo=mdates.UTC)
    loc.tick_values(x1, y1)
    # On success, no overflow error shall be thrown 
Example #13
Source File: _converter.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'):
        dates.AutoDateFormatter.__init__(self, locator, tz, defaultfmt)
        # matplotlib.dates._UTC has no _utcoffset called by pandas
        if self._tz is dates.UTC:
            self._tz._utcoffset = self._tz.utcoffset(None)

        # For mpl > 2.0 the format strings are controlled via rcparams
        # so do not mess with them.  For mpl < 2.0 change the second
        # break point and add a musec break point
        if _mpl_le_2_0_0():
            self.scaled[1. / SEC_PER_DAY] = '%H:%M:%S'
            self.scaled[1. / MUSEC_PER_DAY] = '%H:%M:%S.%f' 
Example #14
Source File: _converter.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def _dt_to_float_ordinal(dt):
    """
    Convert :mod:`datetime` to the Gregorian date as UTC float days,
    preserving hours, minutes, seconds and microseconds.  Return value
    is a :func:`float`.
    """
    if (isinstance(dt, (np.ndarray, Index, ABCSeries)
                   ) and is_datetime64_ns_dtype(dt)):
        base = dates.epoch2num(dt.asi8 / 1.0E9)
    else:
        base = dates.date2num(dt)
    return base


# Datetime Conversion 
Example #15
Source File: _converter.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'):
        dates.AutoDateFormatter.__init__(self, locator, tz, defaultfmt)
        # matplotlib.dates._UTC has no _utcoffset called by pandas
        if self._tz is dates.UTC:
            self._tz._utcoffset = self._tz.utcoffset(None)

        # For mpl > 2.0 the format strings are controlled via rcparams
        # so do not mess with them.  For mpl < 2.0 change the second
        # break point and add a musec break point
        if _mpl_le_2_0_0():
            self.scaled[1. / SEC_PER_DAY] = '%H:%M:%S'
            self.scaled[1. / MUSEC_PER_DAY] = '%H:%M:%S.%f' 
Example #16
Source File: _converter.py    From recruit with Apache License 2.0 5 votes vote down vote up
def _dt_to_float_ordinal(dt):
    """
    Convert :mod:`datetime` to the Gregorian date as UTC float days,
    preserving hours, minutes, seconds and microseconds.  Return value
    is a :func:`float`.
    """
    if (isinstance(dt, (np.ndarray, Index, ABCSeries)
                   ) and is_datetime64_ns_dtype(dt)):
        base = dates.epoch2num(dt.asi8 / 1.0E9)
    else:
        base = dates.date2num(dt)
    return base


# Datetime Conversion 
Example #17
Source File: test_dates.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_drange():
    """
    This test should check if drange works as expected, and if all the
    rounding errors are fixed
    """
    start = datetime.datetime(2011, 1, 1, tzinfo=mdates.UTC)
    end = datetime.datetime(2011, 1, 2, tzinfo=mdates.UTC)
    delta = datetime.timedelta(hours=1)
    # We expect 24 values in drange(start, end, delta), because drange returns
    # dates from an half open interval [start, end)
    assert_equal(24, len(mdates.drange(start, end, delta)))

    # if end is a little bit later, we expect the range to contain one element
    # more
    end = end + datetime.timedelta(microseconds=1)
    assert_equal(25, len(mdates.drange(start, end, delta)))

    # reset end
    end = datetime.datetime(2011, 1, 2, tzinfo=mdates.UTC)

    # and tst drange with "complicated" floats:
    # 4 hours = 1/6 day, this is an "dangerous" float
    delta = datetime.timedelta(hours=4)
    daterange = mdates.drange(start, end, delta)
    assert_equal(6, len(daterange))
    assert_equal(mdates.num2date(daterange[-1]), end - delta) 
Example #18
Source File: _converter.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'):
        dates.AutoDateFormatter.__init__(self, locator, tz, defaultfmt)
        # matplotlib.dates._UTC has no _utcoffset called by pandas
        if self._tz is dates.UTC:
            self._tz._utcoffset = self._tz.utcoffset(None) 
Example #19
Source File: _converter.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def _dt_to_float_ordinal(dt):
    """
    Convert :mod:`datetime` to the Gregorian date as UTC float days,
    preserving hours, minutes, seconds and microseconds.  Return value
    is a :func:`float`.
    """
    if (isinstance(dt, (np.ndarray, Index, ABCSeries)
                   ) and is_datetime64_ns_dtype(dt)):
        base = dates.epoch2num(dt.asi8 / 1.0E9)
    else:
        base = dates.date2num(dt)
    return base


# Datetime Conversion 
Example #20
Source File: test_dates.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_tz_utc():
    dt = datetime.datetime(1970, 1, 1, tzinfo=mdates.UTC)
    dt.tzname() 
Example #21
Source File: test_dates.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_drange():
    """
    This test should check if drange works as expected, and if all the
    rounding errors are fixed
    """
    start = datetime.datetime(2011, 1, 1, tzinfo=mdates.UTC)
    end = datetime.datetime(2011, 1, 2, tzinfo=mdates.UTC)
    delta = datetime.timedelta(hours=1)
    # We expect 24 values in drange(start, end, delta), because drange returns
    # dates from an half open interval [start, end)
    assert len(mdates.drange(start, end, delta)) == 24

    # if end is a little bit later, we expect the range to contain one element
    # more
    end = end + datetime.timedelta(microseconds=1)
    assert len(mdates.drange(start, end, delta)) == 25

    # reset end
    end = datetime.datetime(2011, 1, 2, tzinfo=mdates.UTC)

    # and tst drange with "complicated" floats:
    # 4 hours = 1/6 day, this is an "dangerous" float
    delta = datetime.timedelta(hours=4)
    daterange = mdates.drange(start, end, delta)
    assert len(daterange) == 6
    assert mdates.num2date(daterange[-1]) == (end - delta) 
Example #22
Source File: test_dates.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_RRuleLocator_dayrange():
    loc = mdates.DayLocator()
    x1 = datetime.datetime(year=1, month=1, day=1, tzinfo=mdates.UTC)
    y1 = datetime.datetime(year=1, month=1, day=16, tzinfo=mdates.UTC)
    loc.tick_values(x1, y1)
    # On success, no overflow error shall be thrown 
Example #23
Source File: test_dates.py    From neural-network-animation with MIT License 5 votes vote down vote up
def test_drange():
    """
    This test should check if drange works as expected, and if all the
    rounding errors are fixed
    """
    start = datetime.datetime(2011, 1, 1, tzinfo=mdates.UTC)
    end = datetime.datetime(2011, 1, 2, tzinfo=mdates.UTC)
    delta = datetime.timedelta(hours=1)
    # We expect 24 values in drange(start, end, delta), because drange returns
    # dates from an half open interval [start, end)
    assert_equal(24, len(mdates.drange(start, end, delta)))

    # if end is a little bit later, we expect the range to contain one element
    # more
    end = end + datetime.timedelta(microseconds=1)
    assert_equal(25, len(mdates.drange(start, end, delta)))

    # reset end
    end = datetime.datetime(2011, 1, 2, tzinfo=mdates.UTC)

    # and tst drange with "complicated" floats:
    # 4 hours = 1/6 day, this is an "dangerous" float
    delta = datetime.timedelta(hours=4)
    daterange = mdates.drange(start, end, delta)
    assert_equal(6, len(daterange))
    assert_equal(mdates.num2date(daterange[-1]), end - delta) 
Example #24
Source File: converter.py    From Computable with MIT License 5 votes vote down vote up
def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'):
        dates.AutoDateFormatter.__init__(self, locator, tz, defaultfmt)
        # matplotlib.dates._UTC has no _utcoffset called by pandas
        if self._tz is dates.UTC:
            self._tz._utcoffset = self._tz.utcoffset(None)
        self.scaled = {
            365.0: '%Y',
            30.: '%b %Y',
            1.0: '%b %d %Y',
            1. / 24.: '%H:%M:%S',
            1. / 24. / 3600. / 1000.: '%H:%M:%S.%f'
        } 
Example #25
Source File: converter.py    From Computable with MIT License 5 votes vote down vote up
def _dt_to_float_ordinal(dt):
    """
    Convert :mod:`datetime` to the Gregorian date as UTC float days,
    preserving hours, minutes, seconds and microseconds.  Return value
    is a :func:`float`.
    """
    base = dates.date2num(dt)
    return base


### Datetime Conversion 
Example #26
Source File: _converter.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'):
        dates.AutoDateFormatter.__init__(self, locator, tz, defaultfmt)
        # matplotlib.dates._UTC has no _utcoffset called by pandas
        if self._tz is dates.UTC:
            self._tz._utcoffset = self._tz.utcoffset(None)

        # For mpl > 2.0 the format strings are controlled via rcparams
        # so do not mess with them.  For mpl < 2.0 change the second
        # break point and add a musec break point
        if _mpl_le_2_0_0():
            self.scaled[1. / SEC_PER_DAY] = '%H:%M:%S'
            self.scaled[1. / MUSEC_PER_DAY] = '%H:%M:%S.%f' 
Example #27
Source File: _converter.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def _dt_to_float_ordinal(dt):
    """
    Convert :mod:`datetime` to the Gregorian date as UTC float days,
    preserving hours, minutes, seconds and microseconds.  Return value
    is a :func:`float`.
    """
    if (isinstance(dt, (np.ndarray, Index, ABCSeries)
                   ) and is_datetime64_ns_dtype(dt)):
        base = dates.epoch2num(dt.asi8 / 1.0E9)
    else:
        base = dates.date2num(dt)
    return base


# Datetime Conversion 
Example #28
Source File: _converter.py    From recruit with Apache License 2.0 5 votes vote down vote up
def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'):
        dates.AutoDateFormatter.__init__(self, locator, tz, defaultfmt)
        # matplotlib.dates._UTC has no _utcoffset called by pandas
        if self._tz is dates.UTC:
            self._tz._utcoffset = self._tz.utcoffset(None)