Matplotlib – add a point at every click

# draw one point using subplot
# draw a new point at every click 

import matplotlib.pyplot as plt

def onPress(event):
    print(event.xdata, event.ydata)
    xs = list(pnt.get_xdata())
    ys = list(pnt.get_ydata())
    pnt.set_data(xs, ys)
fig, ax = plt.subplots()
pnt, = ax.plot([0],[1], 'ro')
pnt.figure.canvas.mpl_connect('button_press_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