8000 Add update parameter to clear selector method to make it more generic… · matplotlib/matplotlib@c54a3b3 · GitHub
[go: up one dir, main page]

Skip to content

Commit c54a3b3

Browse files
committed
Add update parameter to clear selector method to make it more generic and simplify code
1 parent bddb7f7 commit c54a3b3

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

lib/matplotlib/widgets.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,11 +2062,22 @@ def get_visible(self):
20622062
property(lambda self: self._visible,
20632063
lambda self, value: setattr(self, "_visible", value)))
20642064

2065-
def clear(self):
2066-
"""Clear the selection and set the selector ready to make a new one."""
2065+
def clear(self, update=True):
2066+
"""
2067+
Clear the selection and set the selector ready to make a new one.
2068+
2069+
Parameters
2070+
----------
2071+
update : bool
2072+
Call the `update` method of the selector to remove the selector
2073+
from the figure. If False, the selector will be removed at the
2074+
next draw.
2075+
2076+
"""
20672077
self._selection_completed = False
20682078
self.set_visible(False)
2069-
self.update()
2079+
if update:
2080+
self.update()
20702081

20712082
@property
20722083
def artists(self):
@@ -3069,12 +3080,10 @@ def _release(self, event):
30693080
# either x or y-direction
30703081
minspanxy = (spanx <= self.minspanx or spany <= self.minspany)
30713082
if (self._drawtype != 'none' and minspanxy):
3072-
for artist in self.artists:
3073-
artist.set_visible(False)
30743083
if self._selection_completed:
30753084
# Call onselect, only when the selection is already existing
30763085
self.onselect(self._eventpress, self._eventrelease)
3077-
self._selection_completed = False
3086+
self.clear(update=False)
30783087
else:
30793088
self.onselect(self._eventpress, self._eventrelease)
30803089
self._selection_completed = True

0 commit comments

Comments
 (0)
0