Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1f53c6b

Browse filesBrowse files
committed
Simplify OldAutoLocator and AutoDateLocator.
In both classes the `refresh` method only sets the `_locator` attribute, which is only later called in `__call__` -- but `__call__` also calls `refresh` first. So we can instead inline the contents of `refresh` into `__call__`, get rid of the `refresh` implementation (inheriting the do-nothing implementation of the base class) and get rid of the `_locator` attribute, as this has no publically observable effect. Likewise, `AutoDateLocator.set_axis` can go.
1 parent db55918 commit 1f53c6b
Copy full SHA for 1f53c6b

File tree

Expand file treeCollapse file tree

2 files changed

+14
-32
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-32
lines changed

‎lib/matplotlib/dates.py

Copy file name to clipboardExpand all lines: lib/matplotlib/dates.py
+5-15Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,6 @@ def __init__(self, tz=None, minticks=5, maxticks=None,
12201220
at 6 hour intervals.
12211221
"""
12221222
DateLocator.__init__(self, tz)
1223-
self._locator = YearLocator(tz=tz)
12241223
self._freq = YEARLY
12251224
self._freqs = [YEARLY, MONTHLY, DAILY, HOURLY, MINUTELY,
12261225
SECONDLY, MICROSECONDLY]
@@ -1258,9 +1257,10 @@ def __init__(self, tz=None, minticks=5, maxticks=None,
12581257
range(0, 24), range(0, 60), range(0, 60), None]
12591258

12601259
def __call__(self):
1261-
"""Return the locations of the ticks."""
1262-
self.refresh()
1263-
return self._locator()
1260+
# docstring inherited
1261+
dmin, dmax = self.viewlim_to_dt()
1262+
locator = self.get_locator(dmin, dmax)
1263+
return locator()
12641264

12651265
def tick_values(self, vmin, vmax):
12661266
return self.get_locator(vmin, vmax).tick_values(vmin, vmax)
@@ -1279,15 +1279,6 @@ def nonsingular(self, vmin, vmax):
12791279
vmax = vmax + DAYS_PER_YEAR * 2
12801280
return vmin, vmax
12811281

1282-
def set_axis(self, axis):
1283-
DateLocator.set_axis(self, axis)
1284-
self._locator.set_axis(axis)
1285-
1286-
def refresh(self):
1287-
# docstring inherited
1288-
dmin, dmax = self.viewlim_to_dt()
1289-
self._locator = self.get_locator(dmin, dmax)
1290-
12911282
def _get_unit(self):
12921283
if self._freq in [MICROSECONDLY]:
12931284
return 1. / MUSECONDS_PER_DAY
@@ -1298,8 +1289,7 @@ def _get_unit(self):
12981289
def autoscale(self):
12991290
"""Try to choose the view limits intelligently."""
13001291
dmin, dmax = self.datalim_to_dt()
1301-
self._locator = self.get_locator(dmin, dmax)
1302-
return self._locator.autoscale()
1292+
return self.get_locator(dmin, dmax).autoscale()
13031293

13041294
def get_locator(self, dmin, dmax):
13051295
"""Pick the best locator based on a distance."""

‎lib/matplotlib/ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/ticker.py
+9-17Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2816,33 +2816,25 @@ class OldAutoLocator(Locator):
28162816
"""
28172817
On autoscale this class picks the best MultipleLocator to set the
28182818
view limits and the tick locs.
2819-
28202819
"""
2821-
def __init__(self):
2822-
self._locator = LinearLocator()
28232820

28242821
def __call__(self):
2825-
"""Return the locations of the ticks."""
2826-
self.refresh()
2827-
return self.raise_if_exceeds(self._locator())
2828-
2829-
def tick_values(self, vmin, vmax):
2830-
raise NotImplementedError('Cannot get tick locations for a '
2831-
'%s type.' % type(self))
2832-
2833-
def refresh(self):
28342822
# docstring inherited
28352823
vmin, vmax = self.axis.get_view_interval()
28362824
vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander=0.05)
28372825
d = abs(vmax - vmin)
2838-
self._locator = self.get_locator(d)
2826+
locator = self.get_locator(d)
2827+
return self.raise_if_exceeds(locator())
28392828

2840-
def view_limits(self, vmin, vmax):
2841-
"""Try to choose the view limits intelligently."""
2829+
def tick_values(self, vmin, vmax):
2830+
raise NotImplementedError('Cannot get tick locations for a '
2831+
'%s type.' % type(self))
28422832

2833+
def view_limits(self, vmin, vmax):
2834+
# docstring inherited
28432835
d = abs(vmax - vmin)
2844-
self._locator = self.get_locator(d)
2845-
return self._locator.view_limits(vmin, vmax)
2836+
locator = self.get_locator(d)
2837+
return locator.view_limits(vmin, vmax)
28462838

28472839
def get_locator(self, d):
28482840
"""Pick the best locator based on a distance *d*."""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.