Last active
December 1, 2017 15:32
-
-
Save erikaris/dad705cac1c110104b65d05bbd7cb0df 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
# taken from: https://stackoverflow.com/questions/5600370/python-matplotlib-add-and-remove-text-to-figure-using-button-events#answer-5600964 | |
txt = None | |
def onclick(event): | |
global txt # why global txt? because there's a variable assignment | |
txt = plt.text(event.xdata, event.ydata, 'TESTTEST', fontsize=8) | |
fig.canvas.draw() | |
def offclick(event): | |
txt.remove() # why there's no global txt? because there's no variable assignment | |
fig.canvas.draw() | |
fig.canvas.mpl_connect('button_press_event', onclick) | |
fig.canvas.mpl_connect('button_release_event', offclick) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment