From 373b9657bd582c0bc9cc214c4f5fb374cba72e83 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sat, 18 Feb 2017 17:57:25 -0800 Subject: [PATCH] Deprecate MAXTICKS, Locator.raise_if_exceeds. --- lib/matplotlib/dates.py | 2 +- lib/matplotlib/tests/test_dates.py | 20 -------------------- lib/matplotlib/ticker.py | 28 ++++++++++++++-------------- 3 files changed, 15 insertions(+), 35 deletions(-) diff --git a/lib/matplotlib/dates.py b/lib/matplotlib/dates.py index 762743259c1b..bc824eece7d1 100644 --- a/lib/matplotlib/dates.py +++ b/lib/matplotlib/dates.py @@ -901,7 +901,7 @@ def tick_values(self, vmin, vmax): dates = self.rule.between(vmin, vmax, True) if len(dates) == 0: return date2num([vmin, vmax]) - return self.raise_if_exceeds(date2num(dates)) + return date2num(dates) def _get_unit(self): """ diff --git a/lib/matplotlib/tests/test_dates.py b/lib/matplotlib/tests/test_dates.py index 437482f5fa2e..d11bdd7a66f0 100644 --- a/lib/matplotlib/tests/test_dates.py +++ b/lib/matplotlib/tests/test_dates.py @@ -86,26 +86,6 @@ def test_date_axvline(): fig.autofmt_xdate() -def test_too_many_date_ticks(): - # Attempt to test SF 2715172, see - # https://sourceforge.net/tracker/?func=detail&aid=2715172&group_id=80706&atid=560720 - # setting equal datetimes triggers and expander call in - # transforms.nonsingular which results in too many ticks in the - # DayLocator. This should trigger a Locator.MAXTICKS RuntimeError - t0 = datetime.datetime(2000, 1, 20) - tf = datetime.datetime(2000, 1, 20) - fig = plt.figure() - ax = fig.add_subplot(1, 1, 1) - with pytest.warns(UserWarning) as rec: - ax.set_xlim((t0, tf), auto=True) - assert len(rec) == 1 - assert 'Attempting to set identical left==right' in str(rec[0].message) - ax.plot([], []) - ax.xaxis.set_major_locator(mdates.DayLocator()) - with pytest.raises(RuntimeError): - fig.savefig('junk.png') - - @image_comparison(baseline_images=['RRuleLocator_bounds'], extensions=['png']) def test_RRuleLocator(): import matplotlib.testing.jpl_units as units diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index d54adc7d0a6a..18f61cd42d0e 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -1422,7 +1422,10 @@ class Locator(TickHelper): # kill the machine when you try and render them. # This parameter is set to cause locators to raise an error if too # many ticks are generated. - MAXTICKS = 1000 + @property + @cbook.deprecated("2.1") + def MAXTICKS(self): + return 1000 def tick_values(self, vmin, vmax): """ @@ -1455,6 +1458,7 @@ def __call__(self): # hence there is no *one* interface to call self.tick_values. raise NotImplementedError('Derived must override') + @cbook.deprecated("2.1") def raise_if_exceeds(self, locs): """raise a RuntimeError if Locator attempts to create more than MAXTICKS locs""" @@ -1581,7 +1585,7 @@ def tick_values(self, vmin, vmax): ticks1 = self.locs[i::step] if np.abs(ticks1).min() < np.abs(ticks).min(): ticks = ticks1 - return self.raise_if_exceeds(ticks) + return ticks class NullLocator(Locator): @@ -1640,18 +1644,14 @@ def tick_values(self, vmin, vmax): vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander=0.05) if vmax < vmin: vmin, vmax = vmax, vmin - if (vmin, vmax) in self.presets: return self.presets[(vmin, vmax)] - if self.numticks is None: self._set_numticks() - if self.numticks == 0: return [] ticklocs = np.linspace(vmin, vmax, self.numticks) - - return self.raise_if_exceeds(ticklocs) + return ticklocs def _set_numticks(self): self.numticks = 11 # todo; be smart here; this is just for dev @@ -1751,7 +1751,7 @@ def tick_values(self, vmin, vmax): base = self._base.get_base() n = (vmax - vmin + 0.001 * base) // base locs = vmin - base + np.arange(n + 3) * base - return self.raise_if_exceeds(locs) + return locs def view_limits(self, dmin, dmax): """ @@ -1966,7 +1966,7 @@ def tick_values(self, vmin, vmax): locs = locs[:-1] elif prune == 'both': locs = locs[1:-1] - return self.raise_if_exceeds(locs) + return locs def view_limits(self, dmin, dmax): if self._symmetric: @@ -2174,7 +2174,7 @@ def tick_values(self, vmin, vmax): else: ticklocs = b ** decades - return self.raise_if_exceeds(np.asarray(ticklocs)) + return np.asarray(ticklocs) def view_limits(self, vmin, vmax): 'Try to choose the view limits intelligently' @@ -2355,7 +2355,7 @@ def get_log_range(lo, hi): else: ticklocs = decades - return self.raise_if_exceeds(np.array(ticklocs)) + return np.array(ticklocs) def view_limits(self, vmin, vmax): 'Try to choose the view limits intelligently' @@ -2446,7 +2446,7 @@ def tick_values(self, vmin, vmax): newticks = 1 - np.outer(np.arange(2, 10), 10**expo).ravel() ticklocs.extend(list(newticks)) - return self.raise_if_exceeds(np.array(ticklocs)) + return np.array(ticklocs) def nonsingular(self, vmin, vmax): initial_range = (1e-7, 1 - 1e-7) @@ -2553,7 +2553,7 @@ def __call__(self): cond = np.abs((locs - t0) % majorstep) > minorstep / 10.0 locs = locs.compress(cond) - return self.raise_if_exceeds(np.array(locs)) + return np.array(locs) def tick_values(self, vmin, vmax): raise NotImplementedError('Cannot get tick locations for a ' @@ -2572,7 +2572,7 @@ def __init__(self): def __call__(self): 'Return the locations of the ticks' self.refresh() - return self.raise_if_exceeds(self._locator()) + return self._locator() def tick_values(self, vmin, vmax): raise NotImplementedError('Cannot get tick locations for a '