Skip to content

Commit 8baad5a

Browse files
committed
Deprecate {Locator,Formatter}.set_{{view,data}_interval,bounds}.
Directly manipulating the underlying axis' view and data intervals is clearer (see e.g. the changes in dates.py which ultimately just deletes code that sets `self.axis`'s view and data intervals to themselves).
1 parent eca2854 commit 8baad5a

File tree

7 files changed

+23
-28
lines changed

7 files changed

+23
-28
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Deprecations
2+
````````````
3+
4+
The ``set_view_interval``, ``set_data_interval`` and ``set_bounds`` methods
5+
of Locators and Formatters (and their common base class, TickHelper) are
6+
deprecated. Directly manipulate the view and data intervals on the underlying
7+
axis instead.

lib/matplotlib/collections.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,8 @@ def legend_elements(self, prop="colors", num="auto",
957957
raise ValueError("Valid values for `prop` are 'colors' or "
958958
f"'sizes'. You supplied '{prop}' instead.")
959959

960-
fmt.set_bounds(func(u).min(), func(u).max())
960+
fmt.axis.set_view_interval(func(u).min(), func(u).max())
961+
fmt.axis.set_data_interval(func(u).min(), func(u).max())
961962
if num == "auto":
962963
num = 9
963964
if len(u) <= num:

lib/matplotlib/colorbar.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -830,11 +830,9 @@ def _ticker(self, locator, formatter):
830830
else:
831831
intv = self.vmin, self.vmax
832832
locator.create_dummy_axis(minpos=intv[0])
833-
formatter.create_dummy_axis(minpos=intv[0])
834-
locator.set_view_interval(*intv)
835-
locator.set_data_interval(*intv)
836-
formatter.set_view_interval(*intv)
837-
formatter.set_data_interval(*intv)
833+
locator.axis.set_view_interval(*intv)
834+
locator.axis.set_data_interval(*intv)
835+
formatter.set_axis(locator.axis)
838836

839837
b = np.array(locator())
840838
if isinstance(locator, ticker.LogLocator):

lib/matplotlib/dates.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,10 +1467,6 @@ def get_locator(self, dmin, dmax):
14671467
'documentation for details.')
14681468

14691469
locator.set_axis(self.axis)
1470-
1471-
if self.axis is not None:
1472-
locator.set_view_interval(*self.axis.get_view_interval())
1473-
locator.set_data_interval(*self.axis.get_data_interval())
14741470
return locator
14751471

14761472

@@ -1728,14 +1724,6 @@ def set_axis(self, axis):
17281724
self._wrapped_locator.set_axis(axis)
17291725
return DateLocator.set_axis(self, axis)
17301726

1731-
def set_view_interval(self, vmin, vmax):
1732-
self._wrapped_locator.set_view_interval(vmin, vmax)
1733-
return DateLocator.set_view_interval(self, vmin, vmax)
1734-
1735-
def set_data_interval(self, vmin, vmax):
1736-
self._wrapped_locator.set_data_interval(vmin, vmax)
1737-
return DateLocator.set_data_interval(self, vmin, vmax)
1738-
17391727
def __call__(self):
17401728
# if no data have been set, this will tank with a ValueError
17411729
try:

lib/matplotlib/tests/test_dates.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,7 @@ def test_auto_date_locator():
308308
def _create_auto_date_locator(date1, date2):
309309
locator = mdates.AutoDateLocator(interval_multiples=False)
310310
locator.create_dummy_axis()
311-
locator.set_view_interval(mdates.date2num(date1),
312-
mdates.date2num(date2))
311+
locator.axis.set_view_interval(*mdates.date2num([date1, date2]))
313312
return locator
314313

315314
d1 = datetime.datetime(1990, 1, 1)
@@ -378,8 +377,7 @@ def test_auto_date_locator_intmult():
378377
def _create_auto_date_locator(date1, date2):
379378
locator = mdates.AutoDateLocator(interval_multiples=True)
380379
locator.create_dummy_axis()
381-
locator.set_view_interval(mdates.date2num(date1),
382-
mdates.date2num(date2))
380+
locator.axis.set_view_interval(*mdates.date2num([date1, date2]))
383381
return locator
384382

385383
results = ([datetime.timedelta(weeks=52 * 200),
@@ -504,8 +502,7 @@ def test_auto_date_locator_intmult_tz():
504502
def _create_auto_date_locator(date1, date2, tz):
505503
locator = mdates.AutoDateLocator(interval_multiples=True, tz=tz)
506504
locator.create_dummy_axis()
507-
locator.set_view_interval(mdates.date2num(date1),
508-
mdates.date2num(date2))
505+
locator.axis.set_view_interval(*mdates.date2num([date1, date2]))
509506
return locator
510507

511508
results = ([datetime.timedelta(weeks=52*200),
@@ -722,8 +719,8 @@ def test_yearlocator_pytz():
722719
+ datetime.timedelta(i) for i in range(2000)]
723720
locator = mdates.AutoDateLocator(interval_multiples=True, tz=tz)
724721
locator.create_dummy_axis()
725-
locator.set_view_interval(mdates.date2num(x[0])-1.0,
726-
mdates.date2num(x[-1])+1.0)
722+
locator.axis.set_view_interval(mdates.date2num(x[0])-1.0,
723+
mdates.date2num(x[-1])+1.0)
727724

728725
np.testing.assert_allclose([733408.208333, 733773.208333, 734138.208333,
729726
734503.208333, 734869.208333,

lib/matplotlib/ticker.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,17 @@ def create_dummy_axis(self, **kwargs):
227227
if self.axis is None:
228228
self.axis = _DummyAxis(**kwargs)
229229

230+
@cbook.deprecated("3.2", alternative=".axis.set_view_interval")
230231
def set_view_interval(self, vmin, vmax):
231232
self.axis.set_view_interval(vmin, vmax)
232233

234+
@cbook.deprecated("3.2", alternative=".axis.set_data_interval")
233235
def set_data_interval(self, vmin, vmax):
234236
self.axis.set_data_interval(vmin, vmax)
235237

238+
@cbook.deprecated(
239+
"3.2",
240+
alternative=".axis.set_view_interval and .axis.set_data_interval")
236241
def set_bounds(self, vmin, vmax):
237242
self.set_view_interval(vmin, vmax)
238243
self.set_data_interval(vmin, vmax)

lib/mpl_toolkits/axisartist/grid_finder.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,7 @@ def __init__(self, nbins=10, steps=None,
233233
self._factor = 1
234234

235235
def __call__(self, v1, v2):
236-
self.set_bounds(v1 * self._factor, v2 * self._factor)
237-
locs = mticker.MaxNLocator.__call__(self)
236+
locs = super().tick_values(v1 * self._factor, v2 * self._factor)
238237
return np.array(locs), len(locs), self._factor
239238

240239
def set_factor(self, f):

0 commit comments

Comments
 (0)