Try it out on an interactive chart first, so any help is appreciated.
I am trying to get an interactive matplotlib graph where points overlap every time I click. Points should be plotted at the click location and on top of the image. I think I figured out how to do this, but I'm wondering if there is an easy way to add a cancel button so that I can delete the last plotted point, if necessary. In the same idea, I would also like to add a “reset” (that is, Delete all points) and “save” buttons.
from matplotlib import pyplot as plt
def onclick(event):
button=event.button
x=event.xdata
y=event.ydata
if button==1: plt.plot(x,y,'ro')
if button!=1: plt.plot(x,y,'bo')
print 'button=%d, x=%d, y=%d, xdata=%f, ydata=%f'%(
event.button, event.x, event.y, event.xdata, event.ydata)
im = plt.imread('Picture1.png')
fig, ax=plt.subplots()
ax.imshow(im)
ax.autoscale(False)
cid = fig.canvas.mpl_connect('button_press_event', onclick)
plt.show()
source
share