I'm trying to update a matplotlib plot with a new data point when a user clicks on the graph. How can I achieve this? I've tried using things like plt.draw() without any success. Here's my attempt so far. I feel I'm missing something fundamental here.
x=[1]
y=[1]
def onclick(event):
if event.button == 1:
x.append(event.xdata)
y.append(event.ydata)
fig,ax=plt.subplots()
ax.scatter(x,y)
fig.canvas.mpl_connect('button_press_event',onclick)
plt.show()
plt.draw()