0
我的图中有很少的注释是用鼠标点击激活的。我想更新一个特定的注释。但是,注释覆盖了较早的注释。如何清除旧的特定/特定注释并用新值更新,以使其看起来干净。更新matplotlib中的特定注释
from matplotlib import pyplot as plt
fig, ax = plt.subplots()
x=1
def annotate():
global x
if x==1:
x=-1
else:
x=1
ax.annotate(x, (0.5,0.5), textcoords='data', size=10)
ax.annotate('Other annotation', (0.5,0.4), textcoords='data', size=10)
def onclick(event):
annotate()
fig.canvas.draw()
cid = fig.canvas.mpl_connect('button_press_event',onclick)
这就是我当时正好在寻找。谢谢。 –