In this code snippet:
import matplotlib.pyplot as plt
import numpy as np
def onclick(event):
plt.text(event.xdata, event.ydata, f'x', color='black')
plt.show()
fig, ax = plt.subplots()
fig.canvas.mpl_connect('button_press_event', onclick)
data = np.random.rand(8, 8)
plt.imshow(data, origin='lower', interpolation='None', aspect='equal')
plt.axis('off')
plt.show()
each mouse click leaves an additional letter x on top of the image:
I would like to have only the most recent x shown. How to accomplish it, while keeping it simple?
