0

In Matplotlib, Python, I want to click and mark points (actually, a point calculated from its position, eventually), but it doesn't seem to be possible. Even something simple like this doesn't work:

from pylab import *

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(np.random.rand(10))

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

cid = fig.canvas.mpl_connect('button_press_event', onclick)
show()
NoBugs
  • 9,310
  • 13
  • 80
  • 146

1 Answers1

1

',' is the marker for a single pixel, try 'o' or something larger instead.

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(np.random.rand(10))

def onclick(event):
    print 'button=%d, x=%d, y=%d, xdata=%f, ydata=%f'%(
        event.button, event.x, event.y, event.xdata, event.ydata)
    ax.plot(event.xdata,event.ydata,'o')
    plt.draw_if_interactive()

cid = fig.canvas.mpl_connect('button_press_event', onclick)
show()

enter image description here

tacaswell
  • 84,579
  • 22
  • 210
  • 199