# draw one point using subplot
# click on the point and drag it around
import matplotlib.pyplot as plt
press = False
def onPress(event):
global press
contains, _ = pnt.contains(event)
# make sure the click is on the object
if contains:
press = True
print(press)
def onMove(event):
global press
if press == True:
# only for events inside the axes
if event.inaxes == pnt.axes:
print(event.xdata, event.ydata)
pnt.set_data([event.xdata, event.ydata])
pnt.figure.canvas.draw()
def onRelease(event):
global press
press = False
print(press)
pnt.figure.canvas.draw()
fig, ax = plt.subplots()
pnt, = ax.plot([0],[1], 'ro')
pnt.figure.canvas.mpl_connect('button_press_event', onPress)
pnt.figure.canvas.mpl_connect('motion_notify_event', onMove)
pnt.figure.canvas.mpl_connect('button_release_event', onRelease)
plt.show()