Skip to content

Instantly share code, notes, and snippets.

@MarcoYcaza
Last active April 4, 2021 02:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcoYcaza/cf1b03abfd070755a884a27b4a46d5cb to your computer and use it in GitHub Desktop.
Save MarcoYcaza/cf1b03abfd070755a884a27b4a46d5cb to your computer and use it in GitHub Desktop.
Allow to draw points on plot
import matplotlib.pyplot as plt
import numpy as np
from numpy import save
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xlim([0, 10])
ax.set_ylim([0, 10])
points_storage=[]
def onclick(event):
print('button=%d, x=%d, y=%d, xdata=%f, ydata=%f' %
(event.button, event.x, event.y, event.xdata, event.ydata))
plt.plot(event.xdata, event.ydata, 'o',markersize=5)
fig.canvas.draw()
points_storage.append([event.xdata, event.ydata])
cid = fig.canvas.mpl_connect('button_press_event', onclick)
plt.show()
acumulado =np.asarray(points_storage)
np.save('puntos.npy', acumulado)
print(acumulado)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment