Skip to content

Commit 9c7858d

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 ae73a46 commit 9c7858d

File tree

7 files changed

+25
-34
lines changed

7 files changed

+25
-34
lines changed
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

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

962-
fmt.set_bounds(func(u).min(), func(u).max())
962+
fmt.axis.set_view_interval(func(u).min(), func(u).max())
963+
fmt.axis.set_data_interval(func(u).min(), func(u).max())
963964
if num == "auto":
964965
num = 9
965966
if len(u) <= num:

lib/matplotlib/colorbar.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -841,11 +841,9 @@ def _ticker(self, locator, formatter):
841841
else:
842842
intv = self.vmin, self.vmax
843843
locator.create_dummy_axis(minpos=intv[0])
844-
formatter.create_dummy_axis(minpos=intv[0])
845-
locator.set_view_interval(*intv)
846-
locator.set_data_interval(*intv)
847-
formatter.set_view_interval(*intv)
848-
formatter.set_data_interval(*intv)
844+
locator.axis.set_view_interval(*intv)
845+
locator.axis.set_data_interval(*intv)
846+
formatter.set_axis(locator.axis)
849847

850848
b = np.array(locator())
851849
if isinstance(locator, ticker.LogLocator):

lib/matplotlib/dates.py

-12
Original file line numberDiff line numberDiff line change
@@ -1567,10 +1567,6 @@ def get_locator(self, dmin, dmax):
15671567
'documentation for details.')
15681568

15691569
locator.set_axis(self.axis)
1570-
1571-
if self.axis is not None:
1572-
locator.set_view_interval(*self.axis.get_view_interval())
1573-
locator.set_data_interval(*self.axis.get_data_interval())
15741570
return locator
15751571

15761572

@@ -1829,14 +1825,6 @@ def set_axis(self, axis):
18291825
self._wrapped_locator.set_axis(axis)
18301826
return DateLocator.set_axis(self, axis)
18311827

1832-
def set_view_interval(self, vmin, vmax):
1833-
self._wrapped_locator.set_view_interval(vmin, vmax)
1834-
return DateLocator.set_view_interval(self, vmin, vmax)
1835-
1836-
def set_data_interval(self, vmin, vmax):
1837-
self._wrapped_locator.set_data_interval(vmin, vmax)
1838-
return DateLocator.set_data_interval(self, vmin, vmax)
1839-
18401828
def __call__(self):
18411829
# if no data have been set, this will tank with a ValueError
18421830
try:

lib/matplotlib/tests/test_dates.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,7 @@ def test_auto_date_locator():
367367
def _create_auto_date_locator(date1, date2):
368368
locator = mdates.AutoDateLocator(interval_multiples=False)
369369
locator.create_dummy_axis()
370-
locator.set_view_interval(mdates.date2num(date1),
371-
mdates.date2num(date2))
370+
locator.axis.set_view_interval(*mdates.date2num([date1, date2]))
372371
return locator
373372

374373
d1 = datetime.datetime(1990, 1, 1)
@@ -437,8 +436,7 @@ def test_auto_date_locator_intmult():
437436
def _create_auto_date_locator(date1, date2):
438437
locator = mdates.AutoDateLocator(interval_multiples=True)
439438
locator.create_dummy_axis()
440-
locator.set_view_interval(mdates.date2num(date1),
441-
mdates.date2num(date2))
439+
locator.axis.set_view_interval(*mdates.date2num([date1, date2]))
442440
return locator
443441

444442
results = ([datetime.timedelta(weeks=52 * 200),
@@ -563,8 +561,7 @@ def test_auto_date_locator_intmult_tz():
563561
def _create_auto_date_locator(date1, date2, tz):
564562
locator = mdates.AutoDateLocator(interval_multiples=True, tz=tz)
565563
locator.create_dummy_axis()
566-
locator.set_view_interval(mdates.date2num(date1),
567-
mdates.date2num(date2))
564+
locator.axis.set_view_interval(*mdates.date2num([date1, date2]))
568565
return locator
569566

570567
results = ([datetime.timedelta(weeks=52*200),
@@ -784,8 +781,8 @@ def test_yearlocator_pytz():
784781
+ datetime.timedelta(i) for i in range(2000)]
785782
locator = mdates.AutoDateLocator(interval_multiples=True, tz=tz)
786783
locator.create_dummy_axis()
787-
locator.set_view_interval(mdates.date2num(x[0])-1.0,
788-
mdates.date2num(x[-1])+1.0)
784+
locator.axis.set_view_interval(mdates.date2num(x[0])-1.0,
785+
mdates.date2num(x[-1])+1.0)
789786

790787
np.testing.assert_allclose([733408.208333, 733773.208333, 734138.208333,
791788
734503.208333, 734869.208333,

lib/matplotlib/ticker.py

+5
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

+3-8
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,9 @@ def __init__(self, nbins=10, steps=None,
249249
self._factor = None
250250

251251
def __call__(self, v1, v2):
252-
if self._factor is not None:
253-
self.set_bounds(v1*self._factor, v2*self._factor)
254-
locs = mticker.MaxNLocator.__call__(self)
255-
return np.array(locs), len(locs), self._factor
256-
else:
257-
self.set_bounds(v1, v2)
258-
locs = mticker.MaxNLocator.__call__(self)
259-
return np.array(locs), len(locs), None
252+
factor = self._factor if self._factor is not None else 1
253+
locs = super().tick_values(v1 * factor, v2 * factor)
254+
return np.array(locs), len(locs), self._factor
260255

261256
def set_factor(self, f):
262257
self._factor = f

0 commit comments

Comments
 (0)