Skip to content

Bug : (minor) time axis labels show "%f" instead of microseconds for years up to 1900 #3179

Closed

Description

@azjps

When plotting with a timestamp-based axis with datetimes of years <= 1900, upon zooming into sub-second scales, the default axis label date formatter shows "%f" instead of microseconds.

In [52]: import time, datetime, matplotlib.dates as mdates

In [53]: dt = mdates.date2num(datetime.datetime(1900, 1, 1, 10, 0))

In [54]: mdates.DateFormatter("%H:%M:%S.%f")(dt)
Out[54]: u'10:00:00.%f'

In [55]: time.strftime("%H:%M:%S.%f", (2000,) + mdates.num2date(dt).timetuple()[1:])
Out[55]: '10:00:00.%f'

This is since timetuple doesn't carry microsecond data. Minor in nature (was using a sentinel date of 1900 without realizing matplotlib would handle it specially) but I figured I would point it out.

Activity

  1. changed the title [-]Bug : (minor) time.strftime doesn't carry microseconds[/-] [+]Bug : (minor) time axis labels show "%f" instead of microseconds for years <= 1900[/+] on Jul 2, 2014
  2. changed the title [-]Bug : (minor) time axis labels show "%f" instead of microseconds for years <= 1900[/-] [+]Bug : (minor) time axis labels show "%f" instead of microseconds for years upto 1900[/+] on Jul 2, 2014
  3. changed the title [-]Bug : (minor) time axis labels show "%f" instead of microseconds for years upto 1900[/-] [+]Bug : (minor) time axis labels show "%f" instead of microseconds for years up to 1900[/+] on Jul 2, 2014
  4. pelson commented on Jul 2, 2014

    @pelson
    Member

    Good spot @azjps, and thanks for making it easy to reproduce. Are you interested in having a go at implementing a fix for this?

  5. azjps commented on Jul 2, 2014

    @azjps
    ContributorAuthor

    Sure :) It seems to me that these three lines in dates.DateFormatter.strftime:

    timetuple = dt.timetuple()
    s1 = time.strftime(fmt, (year,) + timetuple[1:])
    s2 = time.strftime(fmt, (year + 28,) + timetuple[1:])

    could be replaced by

    s1 = dt.replace(year=year).strftime(fmt)
    s2 = dt.replace(year=year+28).strftime(fmt)

    although someone should check that setting to this year in a datetime object will not somehow re-introduce the year before 1900 issue that dates.DateFormatter.stftime was trying to resolve. It seems the updated year value indeed is between 1973 and 2000. I'll submit a pull request in a bit.

  6. added a commit that references this issue on Jul 3, 2014
    b177ae9
  7. modified the milestones: v1.4.0, v1.4.x on Jul 12, 2014
  8. modified the milestones: , v1.4.x on Feb 7, 2015
  9. added 2 commits that reference this issue on Feb 24, 2015
    b208e4a
    e8fb275
  10. added 2 commits that reference this issue on May 25, 2015
    4ce732a
    268ca34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions