This Page

Quick search

#!/usr/bin/env python"""An example of how to interact with the plotting canvas by connectingto move and click events"""from__future__importprint_functionimportsysfrompylabimport*t=arange(0.0,1.0,0.01)s=sin(2*pi*t)fig,ax=plt.subplots()ax.plot(t,s)defon_move(event):# get the x and y pixel coordsx,y=event.x,event.yifevent.inaxes:ax=event.inaxes# the axes instanceprint('data coords %f%f'%(event.xdata,event.ydata))defon_click(event):# get the x and y coords, flip y from top to bottomx,y=event.x,event.yifevent.button==1:ifevent.inaxesisnotNone:print('data coords %f%f'%(event.xdata,event.ydata))binding_id=connect('motion_notify_event',on_move)connect('button_press_event',on_click)if"test_disconnect"insys.argv:print("disconnecting console coordinate printout...")disconnect(binding_id)show()