更新时间:2023-11-30 16:18:58
假设你应该在一个类中使用它并且将下面的 txt
引用为 self.txt
我为方便起见,请在此处使用 global:
Assuming you should use it in a class and refer to the following txt
as self.txt
I use global here for sake of ease:
txt = None
def onclick(event):
global txt
txt = plt.text(event.xdata, event.ydata, 'TESTTEST', fontsize=8)
fig.canvas.draw()
def offclick(event):
txt.remove()
fig.canvas.draw()
fig.canvas.mpl_connect('button_press_event', onclick)
fig.canvas.mpl_connect('button_release_event', offclick)
plt.show()