Skip to content

Simplify OldAutoLocator and AutoDateLocator. #15606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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."""
Expand Down
26 changes: 9 additions & 17 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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*."""
Expand Down