I am trying to retrieve an array as an output from a matplotlib event:
import numpy as np
import matplotlib.pyplot as plt
def onclick(event):
global points
try:
points = np.append(points,[[event.xdata,event.ydata]],axis=0)
except NameError:
points = np.array([[event.xdata,event.ydata]])
ax.plot(points[:,0],points[:,1],'o')
plt.draw()
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xlim((0,10))
ax.set_ylim((0,10))
plt.gcf().canvas.mpl_connect('button_press_event',onclick)
plt.show()
Even tough I have declared "points" to be global,
print(points)
returns a NameError. How can I retrieve "points"? Thank you for any help!!

self.points.