I took the following steps to setup an IPython backend in Google Colab notebook:
!pip install ipympl
from google.colab import output
output.enable_custom_widget_manager()
Then I log the (x,y) location of the user's click on a figure:
%matplotlib ipympl
import matplotlib
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
def onclick(event):
ix, iy = event.xdata, event.ydata
print(ix, iy)
cid = fig.canvas.mpl_connect('button_press_event', onclick)
I need the code to wait here until the user selects at least one data point. However, the code will run if I have another command in the same notebook, for example:
print ('done!')
will run without waiting for the user to pick a data point. I tried using this before:
plt.waitforbuttonpress()
print('done!')
However, the compiler gets stuck at plt.waitforbuttonpress() and it doesn't let the user click the figure. Thanks for your help