[SciPy-Dev] Interactive_Plotting incorrect selection of nearest point
julien.delafontaine@ep...
julien.delafontaine@ep...
Wed Jun 1 05:51:37 CDT 2011
Hi,
I used this script from Scipy's Cookbook
http://www.scipy.org/Cookbook/Matplotlib/Interactive_Plotting
As it is, the distance between two points is not well defined, because
for selecting the nearest point around where you click, you want to
minimize the distance in pixels, not depending on different scales for
x and y coordinates. So I suggest this correction (divide coordinates
by the scale of each axis):
def __init__(self, xdata, ydata, annotes, axis=None, xtol=None, ytol=None):
self.data = zip(xdata, ydata, annotes)
self.xrange = max(xdata) - min(xdata)
self.yrange = max(ydata) - min(ydata)
...
def __call__(self, event):
if event.inaxes:
clickX = event.xdata
clickY = event.ydata
if self.axis is None or self.axis==event.inaxes:
annotes = []
for x,y,a in self.data:
if clickX-self.xtol < x < clickX+self.xtol and
clickY-self.ytol < y < clickY+self.ytol :
annotes.append((self.distance(x/self.xrange,clickX/self.xrange,y/self.yrange,clickY/self.yrange),x,y, a)
)
...
Julien Delafontaine
More information about the SciPy-Dev
mailing list