Last active
December 2, 2017 03:32
-
-
Save erikaris/dd45dc2f2ae7dd517e7435740ec14bb7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # modified from https://matplotlib.org/api/backend_bases_api.html#matplotlib.backend_bases.PickEvent | |
| %matplotlib notebook | |
| plt.figure() | |
| plt.gca().plot(np.random.rand(100), 'o', picker=5) # 5 points tolerance | |
| plt.show() | |
| txt=None | |
| def on_pick(event): | |
| global txt | |
| if txt: | |
| txt.remove() | |
| plt.draw() | |
| line = event.artist | |
| xdata, ydata = line.get_data() | |
| ind = event.ind | |
| # plt.gca().set_title('test') | |
| txt = plt.gca().text(0.05, 0.95, 'on pick line: {}'.format(np.array([xdata[ind], ydata[ind]]).T), transform=plt.gca().transAxes, va='top') | |
| # cid = fig.canvas.mpl_connect('pick_event', on_pick) | |
| cid = plt.gcf().canvas.mpl_connect('pick_event', on_pick) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment