Skip to content

dates.date2num bug with daylight switching hour #3896

Closed

Description

@kdebrab

When plotting datetime values using date2num, something strange happens around the hour of daylight switching (matplotlib 1.4.2, pandas 0.15.1, numpy 1.9.1) as shown in the following graph:

import matplotlib.pyplot as plt
import datetime as dt
import pandas as pd
import pytz
from matplotlib.dates import date2num

dt64_utc = pd.date_range(start='2014/03/29 22:00', end='2014/03/30 6:00', freq='min', tz='UTC')
dtmpl_utc = date2num(dt64_utc.astype(dt.datetime))
dt64_bxl = dt64_utc.tz_convert(pytz.timezone('Europe/Brussels'))
dtmpl_bxl = date2num(dt64_bxl.astype(dt.datetime))
dtmpl_bxl_utc = date2num(dt64_bxl.tz_convert('UTC').astype(dt.datetime))
plt.plot(dtmpl_utc, dtmpl_bxl, 'g', label='implicit conversion to UTC by date2num')
plt.plot(dtmpl_utc, dtmpl_bxl_utc, 'b--', label='explicit conversion to UTC before calling date2num')
plt.gca().xaxis_date()
plt.gca().yaxis_date()
plt.grid()
plt.legend()

date2num bug

I assume this is a bug in date2num?

Activity

  1. added this to the v1.4.x milestone on Dec 7, 2014
  2. tacaswell commented on Feb 7, 2015

    @tacaswell
    Member

    Has proposed fix in #3947

  3. modified the milestones: , v1.4.x, on Feb 7, 2015
  4. modified the milestones: , on Jul 16, 2015
  5. tacaswell commented on Mar 21, 2016

    @tacaswell
    Member

    The fix in #3947 does not seem to fix this on master (but the default tick labels look better!)

    so

  6. self-assigned this
    on Jul 25, 2016
  7. modified the milestones: , on Jul 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions