-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Regenerate background when RectangleSelector active-flag is set back on. #17480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Is this only needed for |
And if so, maybe this should override |
set_active calls update_background, so that's fine? |
|
Wait, I forgot to set Also affects |
Do you have an example where this can easily be checked? Is that just a matter of moving the |
I essentially patched the examples to do what diff --git a/examples/widgets/polygon_selector_demo.py b/examples/widgets/polygon_selector_demo.py
index c1340679f3..68de0e0e9a 100644
--- a/examples/widgets/polygon_selector_demo.py
+++ b/examples/widgets/polygon_selector_demo.py
@@ -50,9 +50,17 @@ class SelectFromCollection:
elif len(self.fc) == 1:
self.fc = np.tile(self.fc, (self.Npts, 1))
- self.poly = PolygonSelector(ax, self.onselect)
+ self.poly = PolygonSelector(ax, self.onselect, useblit=False)
self.ind = []
+ self.cid = self.canvas.mpl_connect('key_press_event',
+ self.toggle_selector)
+
+ def toggle_selector(self, event):
+ if event.key == 't':
+ self.poly.set_active(not self.poly.active)
+ print('Selector toggled')
+
def onselect(self, verts):
path = Path(verts)
self.ind = np.nonzero(path.contains_points(self.xys))[0]
diff --git a/examples/widgets/span_selector.py b/examples/widgets/span_selector.py
index 2e720f4c98..3955c8f540 100644
--- a/examples/widgets/span_selector.py
+++ b/examples/widgets/span_selector.py
@@ -46,9 +46,17 @@ def onselect(xmin, xmax):
#
+def toggle_selector(event):
+ if event.key == 't':
+ span.set_active(not span.active)
+ print('Span toggled')
+
+
span = SpanSelector(ax1, onselect, 'horizontal', useblit=True,
rectprops=dict(alpha=0.5, facecolor='red'))
# Set useblit=True on most backends for enhanced performance.
+fig.canvas.mpl_connect('key_press_event', toggle_selector)
+
plt.show() |
OK, moving everything to the base class seems to work. |
Otherwise, if the selector is made inactive and then back to active, the "old" selector gets captured in the background image and spurious appears. No tests because good luck with that, but can be tried with examples/widgets/rectangle_selector.py.
Otherwise, if the selector is made inactive and then back to active, the
"old" selector gets captured in the background image and spurious
appears.
No tests because good luck with that, but can be tried with
examples/widgets/rectangle_selector.py.
Closes #17476.
PR Summary
PR Checklist