I have this function to develop that is about creating a circle on a matplotlib chart at the coordinates of my mouse cursor. If the cursor moves on the plot screen the circle should move too. I am based on the idea that with each movement of the cursor, a circle must be created, and if there was already another circle created in the previous mouse position it should be deleted so that there is always only one circle on the plot. I'm having trouble on deleting the previous circles artists. Any ideas? The code I'm working on is:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(100)
y = x
fig = plt.figure()
ax = plt.subplot(1,1,1)
ax.plot(x, y)
def onmove(event):
cx = event.xdata
cy = event.ydata
c = ax.scatter(cx,cy)
fig.canvas.draw()
cid = fig.canvas.mpl_connect('motion_notify_event', onmove)
plt.show()