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.
def pickBigLine(self, x, y, trans=None):
Return the Line artist under point that is closest to the x, y.
is None, x, and y are in window coords, 0,0 = lower left.
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))
xywin = x,y
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-xt, yt-yt
if xc==0.0 and yc == 0.0: return 1000000.
D = xc*xc + yc*yc
D1 = -(xt-xywin)*yc+(yt-xywin)*xc
D2 = -(yt-xywin)*yc-(xt-xywin)*xc
if D2/D>1.001 or D2/D<-0.001: return 1000000.
artists = self.lines
if not len(artists): return None
ds = [ (dist(a),a) for a in artists]