diff --git a/lib/matplotlib/dates.py b/lib/matplotlib/dates.py index d6c8316effdf..dbd44d32c89b 100644 --- a/lib/matplotlib/dates.py +++ b/lib/matplotlib/dates.py @@ -1220,7 +1220,6 @@ def __init__(self, tz=None, minticks=5, maxticks=None, at 6 hour intervals. """ DateLocator.__init__(self, tz) - self._locator = YearLocator(tz=tz) self._freq = YEARLY self._freqs = [YEARLY, MONTHLY, DAILY, HOURLY, MINUTELY, SECONDLY, MICROSECONDLY] @@ -1258,9 +1257,10 @@ def __init__(self, tz=None, minticks=5, maxticks=None, range(0, 24), range(0, 60), range(0, 60), None] def __call__(self): - """Return the locations of the ticks.""" - self.refresh() - return self._locator() + # docstring inherited + dmin, dmax = self.viewlim_to_dt() + locator = self.get_locator(dmin, dmax) + return locator() def tick_values(self, vmin, vmax): return self.get_locator(vmin, vmax).tick_values(vmin, vmax) @@ -1279,15 +1279,6 @@ def nonsingular(self, vmin, vmax): vmax = vmax + DAYS_PER_YEAR * 2 return vmin, vmax - def set_axis(self, axis): - DateLocator.set_axis(self, axis) - self._locator.set_axis(axis) - - def refresh(self): - # docstring inherited - dmin, dmax = self.viewlim_to_dt() - self._locator = self.get_locator(dmin, dmax) - def _get_unit(self): if self._freq in [MICROSECONDLY]: return 1. / MUSECONDS_PER_DAY @@ -1298,8 +1289,7 @@ def _get_unit(self): def autoscale(self): """Try to choose the view limits intelligently.""" dmin, dmax = self.datalim_to_dt() - self._locator = self.get_locator(dmin, dmax) - return self._locator.autoscale() + return self.get_locator(dmin, dmax).autoscale() def get_locator(self, dmin, dmax): """Pick the best locator based on a distance.""" diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index c12d2ce65ba3..01a76a1335fd 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -2816,33 +2816,25 @@ class OldAutoLocator(Locator): """ On autoscale this class picks the best MultipleLocator to set the view limits and the tick locs. - """ - def __init__(self): - self._locator = LinearLocator() def __call__(self): - """Return the locations of the ticks.""" - self.refresh() - return self.raise_if_exceeds(self._locator()) - - def tick_values(self, vmin, vmax): - raise NotImplementedError('Cannot get tick locations for a ' - '%s type.' % type(self)) - - def refresh(self): # docstring inherited vmin, vmax = self.axis.get_view_interval() vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander=0.05) d = abs(vmax - vmin) - self._locator = self.get_locator(d) + locator = self.get_locator(d) + return self.raise_if_exceeds(locator()) - def view_limits(self, vmin, vmax): - """Try to choose the view limits intelligently.""" + def tick_values(self, vmin, vmax): + raise NotImplementedError('Cannot get tick locations for a ' + '%s type.' % type(self)) + def view_limits(self, vmin, vmax): + # docstring inherited d = abs(vmax - vmin) - self._locator = self.get_locator(d) - return self._locator.view_limits(vmin, vmax) + locator = self.get_locator(d) + return locator.view_limits(vmin, vmax) def get_locator(self, d): """Pick the best locator based on a distance *d*."""