I have few annotations in my plot which are activated with mouse click. I want to update one specific annotation. However, the annotation is overriding the earlier annotation. How do I clear the old specific/particular annotation and update with new value so that it looks clean.
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)