The pick method because of the need to click on edges did not fullfill

my needs. So I wrote a new method Called PickBigLine that does not

required a mouse click close to the edge but close to the line you want

to pick. This is particularly useful after zooming when the edges are

sometimes out of the axis limits.

I also needed to add a new property to Line2D called tag (similar to

matlab) for sorting purposes. I wonder if you have thought of adding

such a possibility to some objects for which it can be very useful.

Thanks,

Paul Crisini

def pickBigLine(self, x, y, trans=None):

"""

Return the Line artist under point that is closest to the x, y.

if trans

is None, x, and y are in window coords, 0,0 = lower left.

Otherwise,

trans is a matplotlib transform that specifies the coordinate system

of x, y.

No need to click on the edge!

"""

if trans is not None:

xywin = trans.xy_tup((x,y))

else:

xywin = x,y

def dist(a):

xdata = a.get_xdata()

ydata = a.get_ydata()

xt, yt = a.get_transform().numerix_x_y(xdata, ydata)

xt, yt = asarray(xt), asarray(yt)

xc, yc = xt[1]-xt[0], yt[1]-yt[0]

if xc==0.0 and yc == 0.0: return 1000000.

D = xc*xc + yc*yc

D1 = -(xt[0]-xywin[0])*yc+(yt[0]-xywin[1])*xc

D2 = -(yt[0]-xywin[1])*yc-(xt[0]-xywin[0])*xc

if D2/D>1.001 or D2/D<-0.001: return 1000000.

return abs(D1/D)

artists = self.lines

if not len(artists): return None

ds = [ (dist(a),a) for a in artists]

ds.sort()

return ds[0][1]