Skip to content

Commit 7662fc6

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 c91d7ef commit 7662fc6

File tree

7 files changed

+25
-20
lines changed

7 files changed

+25
-20
lines changed

doc/api/next_api_changes/deprecations.rst

+7
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,10 @@ The *clear_temp* parameter and attribute of `.FileMovieWriter` is
211211
deprecated. In the future, files placed in a temporary directory (using
212212
``frame_prefix=None``, the default) will be cleared; files placed elsewhere
213213
will not.
214+
215+
Locator and Formatter wrapper methods
216+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
217+
The ``set_view_interval``, ``set_data_interval`` and ``set_bounds`` methods of
218+
`.Locator`\s and `.Formatter`\s (and their common base class, TickHelper) are
219+
deprecated. Directly manipulate the view and data intervals on the underlying
220+
axis instead.

lib/matplotlib/collections.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,8 @@ def legend_elements(self, prop="colors", num="auto",
998998
raise ValueError("Valid values for `prop` are 'colors' or "
999999
f"'sizes'. You supplied '{prop}' instead.")
10001000

1001-
fmt.set_bounds(func(u).min(), func(u).max())
1001+
fmt.axis.set_view_interval(func(u).min(), func(u).max())
1002+
fmt.axis.set_data_interval(func(u).min(), func(u).max())
10021003
if num == "auto":
10031004
num = 9
10041005
if len(u) <= num:

lib/matplotlib/colorbar.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -884,11 +884,9 @@ def _ticker(self, locator, formatter):
884884
else:
885885
intv = self.vmin, self.vmax
886886
locator.create_dummy_axis(minpos=intv[0])
887-
formatter.create_dummy_axis(minpos=intv[0])
888-
locator.set_view_interval(*intv)
889-
locator.set_data_interval(*intv)
890-
formatter.set_view_interval(*intv)
891-
formatter.set_data_interval(*intv)
887+
locator.axis.set_view_interval(*intv)
888+
locator.axis.set_data_interval(*intv)
889+
formatter.set_axis(locator.axis)
892890

893891
b = np.array(locator())
894892
if isinstance(locator, ticker.LogLocator):

lib/matplotlib/dates.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1463,10 +1463,6 @@ def get_locator(self, dmin, dmax):
14631463
'documentation for details.')
14641464

14651465
locator.set_axis(self.axis)
1466-
1467-
if self.axis is not None:
1468-
locator.set_view_interval(*self.axis.get_view_interval())
1469-
locator.set_data_interval(*self.axis.get_data_interval())
14701466
return locator
14711467

14721468

@@ -1725,10 +1721,12 @@ def set_axis(self, axis):
17251721
self._wrapped_locator.set_axis(axis)
17261722
return DateLocator.set_axis(self, axis)
17271723

1724+
@cbook.deprecated("3.3", alternative=".axis.set_view_interval")
17281725
def set_view_interval(self, vmin, vmax):
17291726
self._wrapped_locator.set_view_interval(vmin, vmax)
17301727
return DateLocator.set_view_interval(self, vmin, vmax)
17311728

1729+
@cbook.deprecated("3.3", alternative=".axis.set_data_interval")
17321730
def set_data_interval(self, vmin, vmax):
17331731
self._wrapped_locator.set_data_interval(vmin, vmax)
17341732
return DateLocator.set_data_interval(self, vmin, vmax)

lib/matplotlib/tests/test_dates.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ def test_auto_date_locator():
309309
def _create_auto_date_locator(date1, date2):
310310
locator = mdates.AutoDateLocator(interval_multiples=False)
311311
locator.create_dummy_axis()
312-
locator.set_view_interval(mdates.date2num(date1),
313-
mdates.date2num(date2))
312+
locator.axis.set_view_interval(*mdates.date2num([date1, date2]))
314313
return locator
315314

316315
d1 = datetime.datetime(1990, 1, 1)
@@ -381,8 +380,7 @@ def test_auto_date_locator_intmult():
381380
def _create_auto_date_locator(date1, date2):
382381
locator = mdates.AutoDateLocator(interval_multiples=True)
383382
locator.create_dummy_axis()
384-
locator.set_view_interval(mdates.date2num(date1),
385-
mdates.date2num(date2))
383+
locator.axis.set_view_interval(*mdates.date2num([date1, date2]))
386384
return locator
387385

388386
results = ([datetime.timedelta(weeks=52 * 200),
@@ -655,8 +653,7 @@ def test_auto_date_locator_intmult_tz():
655653
def _create_auto_date_locator(date1, date2, tz):
656654
locator = mdates.AutoDateLocator(interval_multiples=True, tz=tz)
657655
locator.create_dummy_axis()
658-
locator.set_view_interval(mdates.date2num(date1),
659-
mdates.date2num(date2))
656+
locator.axis.set_view_interval(*mdates.date2num([date1, date2]))
660657
return locator
661658

662659
results = ([datetime.timedelta(weeks=52*200),
@@ -874,8 +871,8 @@ def test_yearlocator_pytz():
874871
+ datetime.timedelta(i) for i in range(2000)]
875872
locator = mdates.AutoDateLocator(interval_multiples=True, tz=tz)
876873
locator.create_dummy_axis()
877-
locator.set_view_interval(mdates.date2num(x[0])-1.0,
878-
mdates.date2num(x[-1])+1.0)
874+
locator.axis.set_view_interval(mdates.date2num(x[0])-1.0,
875+
mdates.date2num(x[-1])+1.0)
879876

880877
np.testing.assert_allclose([733408.208333, 733773.208333, 734138.208333,
881878
734503.208333, 734869.208333,

lib/matplotlib/ticker.py

+5
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,17 @@ def create_dummy_axis(self, **kwargs):
226226
if self.axis is None:
227227
self.axis = _DummyAxis(**kwargs)
228228

229+
@cbook.deprecated("3.3", alternative=".axis.set_view_interval")
229230
def set_view_interval(self, vmin, vmax):
230231
self.axis.set_view_interval(vmin, vmax)
231232

233+
@cbook.deprecated("3.3", alternative=".axis.set_data_interval")
232234
def set_data_interval(self, vmin, vmax):
233235
self.axis.set_data_interval(vmin, vmax)
234236

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

lib/mpl_toolkits/axisartist/grid_finder.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,7 @@ def __init__(self, nbins=10, steps=None,
234234
self._factor = 1
235235

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

241240
def set_factor(self, f):

0 commit comments

Comments
 (0)