<code>import matplotlib.pyplot as plt
def onclick(event):
# This prints both times
print(event.xdata, event.ydata)
# This only works the first time
plt.scatter(event.xdata, event.ydata)
for i in range(2):
plt.plot([1, 2, 3, 4])
plt.gca().figure.canvas.mpl_connect('button_press_event', onclick)
with plt.ion():
plt.show(block=True)
</code>