Reputation: 1720
I am using Jupyter Notebook on a remote server (using ssh). I am using matplotlib and I want to save coordinates to annotate pictures to draw bounding boxes.
I used :
collector = []
def onclick(event):
global i, collector
collector.append((event.xdata, event.ydata))
# Open the annotations file to continue to write
target = open('annotation.txt', 'a')
# Write picture and coordinates
target.write(line)
target.write("\n")
i += 1
event.canvas.figure.clear()
event.canvas.figure.gca().imshow(images[i])
fig = plt.figure(figsize=(5,5))
fig.canvas.mpl_connect('button_press_event', onclick)
plt.imshow(images[0])
plt.show()
However, I don't why but it seems to not work anymore. Does someone know a solution to save click events on Jupyter Notebook ?
Thank you very much in advance.
Upvotes: 0
Views: 1622
Reputation: 339220
You are probably using the %matplotlib inline
backend, which does not support any kind of events (since it produces simple png images). In order to work with interactive elements and events, you would want to use the %matplotlib notebook
backend. This means you should put the line
%matplotlib notebook
somewhere upfront your notebook.
Upvotes: 1