I'm trying to write a script that saves the coordinates of the first two mouse clicks on a plot (generated via matplotlib), pausing the script until these clicks occur. I tried to implement the "pause" with a while loop, which should finish once the callback function detects that the mouse has been clicked twice. However, once the while loop starts running, clicking on the plot area seems to have no effect. Any help would be much appreciated.
coords = []
pause = True
fig, ax = plt.subplots()
plt.pcolormesh(x_grid, y_grid, arr)
plt.show()
def onclick(event):
global coords
coords.append((event.xdata, event.ydata))
if (len(coords)==2):
pause = False
fig.canvas.mpl_disconnect(cid)
cid = fig.canvas.mpl_connect('button_press_event', onclick)
while pause:
pass
# ...More code to follow, after the while loop finishes