Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0f7a38f

Browse files
committed
Deprecate Locator.refresh and associated helpers.
`Locator.refresh()` was called at certain places to let locators update their internal state, typically based on the axis limits. Instead, they can just always consult the axis limits when called, if needed. (This should be more robust -- otherwise, a call to a locator basically always needs to be preceded to a call to `refresh()` to ensure getting up-to-date results.) The deprecation is made slightly complex by the fact that we need to check whether the user is using a third-party locator which overrides `refresh()`, and warn in that case. The associated helper methods `NavigationToolbar2.draw()` and `ToolViewsPositions.refresh_locators()` (which called `refresh()` and then `canvas.draw_idle()` are deprecated, and should be replaced by calls to `draw_idle()` on the corresponding canvas once the deprecation period ends.
1 parent f6b8891 commit 0f7a38f

File tree

5 files changed

+45
-8
lines changed

5 files changed

+45
-8
lines changed

doc/api/api_changes_3.3/deprecations.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,3 +439,14 @@ names will be passed as is, allowing one to pass names such as *patchA* or
439439
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
440440
These attributes are deprecated in favor of ``ContourSet.axes`` and
441441
``Quiver.axes``, for consistency with other artists.
442+
443+
``Locator.refresh()`` and associated methods
444+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
445+
``Locator.refresh()`` is deprecated. This method was called at certain places
446+
to let locators update their internal state, typically based on the axis
447+
limits. Locators should now always consult the axis limits when called, if
448+
needed.
449+
450+
The associated helper methods ``NavigationToolbar2.draw()`` and
451+
``ToolViewsPositions.refresh_locators()`` are deprecated, and should be
452+
replaced by calls to ``draw_idle()`` on the corresponding canvas.

lib/matplotlib/backend_bases.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
import numpy as np
4343

44+
import matplotlib as mpl
4445
from matplotlib import (
4546
backend_tools as tools, cbook, colors, textpath, tight_bbox, transforms,
4647
widgets, get_backend, is_interactive, rcParams)
@@ -2983,7 +2984,7 @@ def release_pan(self, event):
29832984
self._button_pressed = None
29842985
self.push_current()
29852986
self.release(event)
2986-
self.draw()
2987+
self._draw()
29872988

29882989
def drag_pan(self, event):
29892990
"""Callback for dragging in pan/zoom mode."""
@@ -3026,7 +3027,7 @@ def release_zoom(self, event):
30263027
(abs(y - start_y) < 5 and event.key != "x")):
30273028
self._xypress = None
30283029
self.release(event)
3029-
self.draw()
3030+
self._draw()
30303031
return
30313032

30323033
# Detect whether this axes is twinned with an earlier axes in the
@@ -3040,14 +3041,20 @@ def release_zoom(self, event):
30403041
(start_x, start_y, x, y), self._zoom_info["direction"],
30413042
event.key, twinx, twiny)
30423043

3043-
self.draw()
3044+
self._draw()
30443045
self._zoom_info = None
30453046

30463047
self.push_current()
30473048
self.release(event)
30483049

3050+
@cbook.deprecated("3.3", alternative="toolbar.canvas.draw_idle()")
30493051
def draw(self):
30503052
"""Redraw the canvases, update the locators."""
3053+
self._draw()
3054+
3055+
# Can be removed once Locator.refresh() is removed, and replaced by an
3056+
# inline call to self.canvas.draw_idle().
3057+
def _draw(self):
30513058
for a in self.canvas.figure.get_axes():
30523059
xaxis = getattr(a, 'xaxis', None)
30533060
yaxis = getattr(a, 'yaxis', None)
@@ -3060,7 +3067,7 @@ def draw(self):
30603067
locators.append(yaxis.get_minor_locator())
30613068

30623069
for loc in locators:
3063-
loc.refresh()
3070+
mpl.ticker._if_refresh_overridden_call_and_emit_deprec(loc)
30643071
self.canvas.draw_idle()
30653072

30663073
def _update_view(self):

lib/matplotlib/backend_tools.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,14 @@ def update_home_views(self, figure=None):
636636
if a not in self.home_views[figure]:
637637
self.home_views[figure][a] = a._get_view()
638638

639+
@cbook.deprecated("3.3", alternative="self.figure.canvas.draw_idle()")
639640
def refresh_locators(self):
640641
"""Redraw the canvases, update the locators."""
642+
self._refresh_locators()
643+
644+
# Can be removed once Locator.refresh() is removed, and replaced by an
645+
# inline call to self.figure.canvas.draw_idle().
646+
def _refresh_locators(self):
641647
for a in self.figure.get_axes():
642648
xaxis = getattr(a, 'xaxis', None)
643649
yaxis = getattr(a, 'yaxis', None)
@@ -654,7 +660,7 @@ def refresh_locators(self):
654660
locators.append(zaxis.get_minor_locator())
655661

656662
for loc in locators:
657-
loc.refresh()
663+
mpl.ticker._if_refresh_overridden_call_and_emit_deprec(loc)
658664
self.figure.canvas.draw_idle()
659665

660666
def home(self):
@@ -808,7 +814,7 @@ def _cancel_action(self):
808814
for zoom_id in self._ids_zoom:
809815
self.figure.canvas.mpl_disconnect(zoom_id)
810816
self.toolmanager.trigger_tool('rubberband', self)
811-
self.toolmanager.get_tool(_views_positions).refresh_locators()
817+
self.toolmanager.get_tool(_views_positions)._refresh_locators()
812818
self._xypress = None
813819
self._button_pressed = None
814820
self._ids_zoom = []
@@ -935,7 +941,7 @@ def _cancel_action(self):
935941
self._xypress = []
936942
self.figure.canvas.mpl_disconnect(self._id_drag)
937943
self.toolmanager.messagelock.release(self)
938-
self.toolmanager.get_tool(_views_positions).refresh_locators()
944+
self.toolmanager.get_tool(_views_positions)._refresh_locators()
939945

940946
def _press(self, event):
941947
if event.button == 1:

lib/matplotlib/projections/polar.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ def pan(self, numsteps):
443443
def zoom(self, direction):
444444
return self.base.zoom(direction)
445445

446+
@cbook.deprecated("3.3")
446447
def refresh(self):
447448
# docstring inherited
448449
return self.base.refresh()

lib/matplotlib/ticker.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,18 @@ def symbol(self, symbol):
15641564
self._symbol = symbol
15651565

15661566

1567+
def _if_refresh_overridden_call_and_emit_deprec(locator):
1568+
if not locator.refresh.__func__.__module__.startswith("matplotlib."):
1569+
cbook.warn_external(
1570+
"3.3", message="Automatic calls to Locator.refresh by the draw "
1571+
"machinery are deprecated since %(since)s and will be removed in "
1572+
"%(removal)s. You are using a third-party locator that overrides "
1573+
"the refresh() method; this locator should instead perform any "
1574+
"required processing in __call__().")
1575+
with cbook._suppress_matplotlib_deprecation_warning():
1576+
locator.refresh()
1577+
1578+
15671579
class Locator(TickHelper):
15681580
"""
15691581
Determine the tick locations;
@@ -1686,9 +1698,9 @@ def zoom(self, direction):
16861698
step = 0.1 * interval * direction
16871699
self.axis.set_view_interval(vmin + step, vmax - step, ignore=True)
16881700

1701+
@cbook.deprecated("3.3")
16891702
def refresh(self):
16901703
"""Refresh internal information based on current limits."""
1691-
pass
16921704

16931705

16941706
class IndexLocator(Locator):

0 commit comments

Comments
 (0)