Skip to content

Deprecate MAXTICKS, Locator.raise_if_exceeds. #8100

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
20 changes: 0 additions & 20 deletions lib/matplotlib/tests/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 '
Expand All @@ -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 '
Expand Down