matplotlibでマウスのボタンが押されたときの情報を取得するプログラム。
ここでの取得項目は左から、
押されたボタンの種類(1:右、2:ホイール、3:左)、
マウスの押された場所でのピクセル座標(x, y)
マウスの押された場所でのデータ座標(x, y)
参考URL:http://matplotlib.sourceforge.net/users/event_handling.html
ここでの取得項目は左から、
押されたボタンの種類(1:右、2:ホイール、3:左)、
マウスの押された場所でのピクセル座標(x, y)
マウスの押された場所でのデータ座標(x, y)
参考URL:http://matplotlib.sourceforge.net/users/event_handling.html
from numpy.random import rand
from pylab import figure, show
def onclick(event):
print 'button=%d, x=%d, y=%d, xdata=%f, ydata=%f'%(
event.button, event.x, event.y, event.xdata, event.ydata)
if __name__ == "__main__":
fig = figure()
ax = fig.add_subplot(111)
ax.set_title("button pressed event demo")
ax.plot(rand(5))
fig.canvas.mpl_connect('button_press_event', onclick)
show()
0 件のコメント:
コメントを投稿