Matplotlib – click and move a point around

# draw one point using subplot
# move the point to the clicked locaction

import matplotlib.pyplot as plt

def onPress(event):
    print(event.xdata, event.ydata)
    pnt.set_data([event.xdata, event.ydata])

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', onPress)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s