Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2225813

Browse filesBrowse files
authored
Merge pull request #13860 from anntzer/getviewdataintervals
Deprecate {Locator,Formatter}.set_{{view,data}_interval,bounds}.
2 parents 153b463 + 21e5876 commit 2225813
Copy full SHA for 2225813

File tree

Expand file treeCollapse file tree

8 files changed

+31
-26
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+31
-26
lines changed
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Locator and Formatter wrapper methods
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
The ``set_view_interval``, ``set_data_interval`` and ``set_bounds`` methods of
4+
`.Locator`\s and `.Formatter`\s (and their common base class, TickHelper) are
5+
deprecated. Directly manipulate the view and data intervals on the underlying
6+
axis instead.

‎lib/matplotlib/collections.py

Copy file name to clipboardExpand all lines: lib/matplotlib/collections.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,9 @@ def legend_elements(self, prop="colors", num="auto",
11281128
raise ValueError("Valid values for `prop` are 'colors' or "
11291129
f"'sizes'. You supplied '{prop}' instead.")
11301130

1131-
fmt.set_bounds(func(u).min(), func(u).max())
1131+
fu = func(u)
1132+
fmt.axis.set_view_interval(fu.min(), fu.max())
1133+
fmt.axis.set_data_interval(fu.min(), fu.max())
11321134
if num == "auto":
11331135
num = 9
11341136
if len(u) <= num:

‎lib/matplotlib/colorbar.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colorbar.py
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -869,11 +869,9 @@ def _ticker(self, locator, formatter):
869869
else:
870870
intv = self.vmin, self.vmax
871871
locator.create_dummy_axis(minpos=intv[0])
872-
formatter.create_dummy_axis(minpos=intv[0])
873-
locator.set_view_interval(*intv)
874-
locator.set_data_interval(*intv)
875-
formatter.set_view_interval(*intv)
876-
formatter.set_data_interval(*intv)
872+
locator.axis.set_view_interval(*intv)
873+
locator.axis.set_data_interval(*intv)
874+
formatter.set_axis(locator.axis)
877875

878876
b = np.array(locator())
879877
if isinstance(locator, ticker.LogLocator):

‎lib/matplotlib/dates.py

Copy file name to clipboardExpand all lines: lib/matplotlib/dates.py
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,10 +1480,6 @@ def get_locator(self, dmin, dmax):
14801480
'epoch.')
14811481

14821482
locator.set_axis(self.axis)
1483-
1484-
if self.axis is not None:
1485-
locator.set_view_interval(*self.axis.get_view_interval())
1486-
locator.set_data_interval(*self.axis.get_data_interval())
14871483
return locator
14881484

14891485

@@ -1727,10 +1723,12 @@ def set_axis(self, axis):
17271723
self._wrapped_locator.set_axis(axis)
17281724
return super().set_axis(axis)
17291725

1726+
@_api.deprecated("3.5", alternative=".axis.set_view_interval")
17301727
def set_view_interval(self, vmin, vmax):
17311728
self._wrapped_locator.set_view_interval(vmin, vmax)
17321729
return super().set_view_interval(vmin, vmax)
17331730

1731+
@_api.deprecated("3.5", alternative=".axis.set_data_interval")
17341732
def set_data_interval(self, vmin, vmax):
17351733
self._wrapped_locator.set_data_interval(vmin, vmax)
17361734
return super().set_data_interval(vmin, vmax)

‎lib/matplotlib/tests/test_dates.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_dates.py
+9-12Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def test_date_formatter_usetex(delta, expected):
280280

281281
locator = mdates.AutoDateLocator(interval_multiples=False)
282282
locator.create_dummy_axis()
283-
locator.set_view_interval(mdates.date2num(d1), mdates.date2num(d2))
283+
locator.axis.set_view_interval(mdates.date2num(d1), mdates.date2num(d2))
284284

285285
formatter = mdates.AutoDateFormatter(locator, usetex=True)
286286
assert [formatter(loc) for loc in locator()] == expected
@@ -319,8 +319,7 @@ def test_auto_date_locator():
319319
def _create_auto_date_locator(date1, date2):
320320
locator = mdates.AutoDateLocator(interval_multiples=False)
321321
locator.create_dummy_axis()
322-
locator.set_view_interval(mdates.date2num(date1),
323-
mdates.date2num(date2))
322+
locator.axis.set_view_interval(*mdates.date2num([date1, date2]))
324323
return locator
325324

326325
d1 = datetime.datetime(1990, 1, 1)
@@ -391,8 +390,7 @@ def test_auto_date_locator_intmult():
391390
def _create_auto_date_locator(date1, date2):
392391
locator = mdates.AutoDateLocator(interval_multiples=True)
393392
locator.create_dummy_axis()
394-
locator.set_view_interval(mdates.date2num(date1),
395-
mdates.date2num(date2))
393+
locator.axis.set_view_interval(*mdates.date2num([date1, date2]))
396394
return locator
397395

398396
results = ([datetime.timedelta(weeks=52 * 200),
@@ -574,7 +572,7 @@ def test_concise_formatter_usetex(t_delta, expected):
574572

575573
locator = mdates.AutoDateLocator(interval_multiples=True)
576574
locator.create_dummy_axis()
577-
locator.set_view_interval(mdates.date2num(d1), mdates.date2num(d2))
575+
locator.axis.set_view_interval(mdates.date2num(d1), mdates.date2num(d2))
578576

579577
formatter = mdates.ConciseDateFormatter(locator, usetex=True)
580578
assert formatter.format_ticks(locator()) == expected
@@ -732,8 +730,7 @@ def test_auto_date_locator_intmult_tz():
732730
def _create_auto_date_locator(date1, date2, tz):
733731
locator = mdates.AutoDateLocator(interval_multiples=True, tz=tz)
734732
locator.create_dummy_axis()
735-
locator.set_view_interval(mdates.date2num(date1),
736-
mdates.date2num(date2))
733+
locator.axis.set_view_interval(*mdates.date2num([date1, date2]))
737734
return locator
738735

739736
results = ([datetime.timedelta(weeks=52*200),
@@ -951,8 +948,8 @@ def test_yearlocator_pytz():
951948
+ datetime.timedelta(i) for i in range(2000)]
952949
locator = mdates.AutoDateLocator(interval_multiples=True, tz=tz)
953950
locator.create_dummy_axis()
954-
locator.set_view_interval(mdates.date2num(x[0])-1.0,
955-
mdates.date2num(x[-1])+1.0)
951+
locator.axis.set_view_interval(mdates.date2num(x[0])-1.0,
952+
mdates.date2num(x[-1])+1.0)
956953
t = np.array([733408.208333, 733773.208333, 734138.208333,
957954
734503.208333, 734869.208333, 735234.208333, 735599.208333])
958955
# convert to new epoch from old...
@@ -1035,8 +1032,8 @@ def test_warn_notintervals():
10351032
locator = mdates.AutoDateLocator(interval_multiples=False)
10361033
locator.intervald[3] = [2]
10371034
locator.create_dummy_axis()
1038-
locator.set_view_interval(mdates.date2num(dates[0]),
1039-
mdates.date2num(dates[-1]))
1035+
locator.axis.set_view_interval(mdates.date2num(dates[0]),
1036+
mdates.date2num(dates[-1]))
10401037
with pytest.warns(UserWarning, match="AutoDateLocator was unable") as rec:
10411038
locs = locator()
10421039

‎lib/matplotlib/tests/test_ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_ticker.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ def test_use_locale(self):
558558
assert tmp_form.get_useLocale()
559559

560560
tmp_form.create_dummy_axis()
561-
tmp_form.set_bounds(0, 10)
561+
tmp_form.axis.set_data_interval(0, 10)
562562
tmp_form.set_locs([1, 2, 3])
563563
assert sep in tmp_form(1e9)
564564

@@ -589,7 +589,7 @@ def test_cursor_dummy_axis(self, data, expected):
589589
# Issue #17624
590590
sf = mticker.ScalarFormatter()
591591
sf.create_dummy_axis()
592-
sf.set_bounds(0, 10)
592+
sf.axis.set_view_interval(0, 10)
593593
fmt = sf.format_data_short
594594
assert fmt(data) == expected
595595

‎lib/matplotlib/ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/ticker.py
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,17 @@ def create_dummy_axis(self, **kwargs):
231231
if self.axis is None:
232232
self.axis = _DummyAxis(**kwargs)
233233

234+
@_api.deprecated("3.5", alternative=".axis.set_view_interval")
234235
def set_view_interval(self, vmin, vmax):
235236
self.axis.set_view_interval(vmin, vmax)
236237

238+
@_api.deprecated("3.5", alternative=".axis.set_data_interval")
237239
def set_data_interval(self, vmin, vmax):
238240
self.axis.set_data_interval(vmin, vmax)
239241

242+
@_api.deprecated(
243+
"3.5",
244+
alternative=".axis.set_view_interval and .axis.set_data_interval")
240245
def set_bounds(self, vmin, vmax):
241246
self.set_view_interval(vmin, vmax)
242247
self.set_data_interval(vmin, vmax)

‎lib/mpl_toolkits/axisartist/grid_finder.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/axisartist/grid_finder.py
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,7 @@ def __init__(self, nbins=10, steps=None,
222222
self._factor = 1
223223

224224
def __call__(self, v1, v2):
225-
self.set_bounds(v1 * self._factor, v2 * self._factor)
226-
locs = super().__call__()
225+
locs = super().tick_values(v1 * self._factor, v2 * self._factor)
227226
return np.array(locs), len(locs), self._factor
228227

229228
@_api.deprecated("3.3")

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.