Hi all,
Is it possible to restrict the mouse movements to the
points of a graph (curve tracking) ?
So far I am able to obtain the location of the mouse in
data coordinates if the mouse is over an axes.
A code snippet is attached.
Thanks in advance.
Nils
from pylab import plot, show, connect, xlabel, ylabel, legend, xlim, ylim
from numpy import linspace, sin, pi, empty
def find_minima(x):
minima = empty((len(x),),dtype=bool)
dx=x[1:]-x[:-1]
minima[1:-1]=(dx[:-1]<=0) & (dx[1:]>=0)
#handle endpoint s
# minima[0]=dx[0]>=0
# minima[-1]=dx[-1]<=0
return minima
x = linspace(0,3*pi,200)
y = sin(x)
plot(x,y,'r.',label=r'$\sin(x)$')
minima = find_minima(-y)
plot(x[minima],y[minima],'ko',label='maxima')
legend()
def on_move(event):
#
# Connect to the mouse move event and print the location of the mouse
# in data coordinates if the mouse is over an axes
#
x,y = event.x, event.y
if event.inaxes:
print 'data coords', event.xdata, event.ydata
#connect('motion_notify_event', on_move)
def click(event):
x,y = event.x, event.y
if event.inaxes:
print 'you clicked', event.xdata, event.ydata
connect('button_press_event',click)
xlim(0,3*pi+0.1)
ylim(-1.1,1.1)
show()
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users