# Supported datetimes with microseconds, and those with long time series (>160 years). #1925

Merged
merged 4 commits into from May 20, 2013

## Conversation

Projects
None yet
4 participants
Member

### pelson commented Apr 19, 2013

 This pull request updates the AutoDateLocator and AutoDateFormatter classes to handle extreme time series (<1 second and >160 years). The follow code demonstrates the problems: import datetime as dt import numpy as np import matplotlib.pyplot as plt d1 = dt.datetime(1990, 1, 1) if False: n = 365 * 200 x = np.array([d1 + dt.timedelta(days=i) for i in range(n)], dtype=object) else: n = int(1e4) x = np.array([d1 + dt.timedelta(microseconds=i * 10) for i in range(n)], dtype=object) y = np.sin(np.linspace(0, np.pi * 2, n)) plt.figure(figsize=(12, 6)) plt.plot(x, y) ax = plt.gca() dt_loc = ax.xaxis.get_major_locator() plt.show() (try running this before this PR to see the improvement)

### NelleV reviewed Apr 22, 2013

 def __call__(self): 'Return the locations of the ticks' self.refresh() return self._locator() + def nonsingular(self, vmin, vmax): + # whatever is thrown at us, we can scale the unit. + # But default nonsigular date plots at an ~4 year period.

#### NelleV Apr 22, 2013

Contributor

Small typo: nonsigular => nonsingular

### NelleV reviewed Apr 22, 2013

 def __call__(self): 'Return the locations of the ticks' self.refresh() return self._locator() + def nonsingular(self, vmin, vmax):

#### NelleV Apr 22, 2013

Contributor

Maybe you can add some documentation on this method?

#### pelson Apr 25, 2013

Member

I've added a docstring on the superclass.

Member

Contributor

### NelleV commented Apr 25, 2013

 LGTM 👍 for merge !

### efiring reviewed May 11, 2013

 @@ -573,6 +577,11 @@ def _get_interval(self): return 1 def nonsingular(self, vmin, vmax): + """ + Given the proposed upper and lower extent, adjust the range + if it is too close to being singlular (i.e. a range of ~0).

Owner

typo: singular

### efiring reviewed May 11, 2013

 + def __init__(self, interval=1, tz=None): + """ + *interval* is the interval between each iteration. For + example, if ``interval=2``, mark every second miscrosecond.

#### efiring May 11, 2013

Owner

typo: microsecond

### efiring reviewed May 11, 2013

 delta = relativedelta(dmax, dmin) - +

#### efiring May 11, 2013

Owner

I'm not positive, but from the github display it looks like this is an insertion of trailing whitespace.

### efiring reviewed May 11, 2013

 @@ -704,7 +713,7 @@ def autoscale(self): class AutoDateLocator(DateLocator): """ On autoscale, this class picks the best - :class:`MultipleDateLocator` to set the view limits and the tick + :class:`RRuleLocator` to set the view limits and the tick

#### efiring May 11, 2013

Owner

Not quite correct; it might return a MicrosecondLocator, which is not a subclass of RRuleLocator. Maybe this should just say "DateLocator". There is a similar comment in the module docstring that needs to be corrected.

Member

### pelson commented May 14, 2013

 Thanks @efiring - I've done all of the above. The dates module is also now completely pep8 compliant. I've also removed the pdf and svg testing, which was not adding any value to the test suite (other than testing the svg and pdf backends which are being tested elsewhere). I think this is good to go.
Owner

### mdboom commented May 14, 2013

 There are some Travis failures here, but once those are resolved, I think this looks good.
Member

### pelson commented May 17, 2013

 I've updated the failing test result (and removed the formats which are not exercising anything new).
Member

### pelson commented May 20, 2013

 Again, I think this is good for merge.

### efiring added a commit that referenced this pull request May 20, 2013

Merge pull request #1925 from pelson/long_timeseries_plots
Supported datetimes with microseconds, and those with long time series (>160 years).

### efiring merged commit f30dc0a into matplotlib:master May 20, 2013 1 check passed

#### 1 check passed

default The Travis CI build passed
Details

Closed

Closed