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

Skip to content

Commit d7f69fe

Browse files
authored
Merge pull request #10308 from anntzer/lasso-selector-no-input
DOC: Switch the lasso selector demo to use mpl event handling, not input().
2 parents 296b5ff + 8e7c133 commit d7f69fe

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

examples/widgets/lasso_selector_demo_sgskip.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
a lasso loop around the points on the graph. To draw, just click
1010
on the graph, hold, and drag it around the points you need to select.
1111
"""
12-
from __future__ import print_function
1312

14-
from six.moves import input
13+
from __future__ import print_function
1514

1615
import numpy as np
1716

@@ -79,7 +78,6 @@ def disconnect(self):
7978
if __name__ == '__main__':
8079
import matplotlib.pyplot as plt
8180

82-
plt.ion()
8381
# Fixing random state for reproducibility
8482
np.random.seed(19680801)
8583

@@ -91,11 +89,15 @@ def disconnect(self):
9189
pts = ax.scatter(data[:, 0], data[:, 1], s=80)
9290
selector = SelectFromCollection(ax, pts)
9391

94-
plt.draw()
95-
input('Press Enter to accept selected points')
96-
print("Selected points:")
97-
print(selector.xys[selector.ind])
98-
selector.disconnect()
92+
def accept(event):
93+
if event.key == "enter":
94+
print("Selected points:")
95+
print(selector.xys[selector.ind])
96+
selector.disconnect()
97+
ax.set_title("")
98+
fig.canvas.draw()
99+
100+
fig.canvas.mpl_connect("key_press_event", accept)
101+
ax.set_title("Press enter to accept selected points.")
99102

100-
# Block end of script so you can check that the lasso is disconnected.
101-
input('Press Enter to quit')
103+
plt.show()

0 commit comments

Comments
 (0)