def find_nearest_contour( self, x, y, indices=None, pixel=True ):
<EOL>if indices==None:<EOL><INDENT>indices = list(range(len(self.levels)))<EOL><DEDENT>dmin = <NUM_LIT><EOL>conmin = None<EOL>segmin = None<EOL>xmin = None<EOL>ymin = None<EOL>for icon in indices:<EOL><INDENT>con = self.collections[icon]<EOL>paths = con.get_paths()<EOL>for segNum, linepath in enumerate(paths):<EOL><INDENT>lc = linepath.vertices<EOL>if pixel:<EOL><INDENT>lc = self.ax.transData.transform(lc)<EOL><DEDENT>ds = (lc[:,<NUM_LIT:0>]-x)**<NUM_LIT:2> + (lc[:,<NUM_LIT:1>]-y)**<NUM_LIT:2><EOL>d = min( ds )<EOL>if d < dmin:<EOL><INDENT>dmin = d<EOL>conmin = icon<EOL>segmin = segNum<EOL>imin = mpl.mlab.find( ds == d )[<NUM_LIT:0>]<EOL>xmin = lc[imin,<NUM_LIT:0>]<EOL>ymin = lc[imin,<NUM_LIT:1>]<EOL><DEDENT><DEDENT><DEDENT>return (conmin,segmin,imin,xmin,ymin,dmin)<EOL>
Finds contour that is closest to a point.  Defaults to
measuring distance in pixels (screen space - useful for manual
contour labeling), but this can be controlled via a keyword
argument.

Returns a tuple containing the contour, segment, index of
segment, x & y of segment point and distance to minimum point.

Call signature::

  conmin,segmin,imin,xmin,ymin,dmin = find_nearest_contour(
             self, x, y, indices=None, pixel=True )

Optional keyword arguments::

*indices*:
   Indexes of contour levels to consider when looking for
   nearest point.  Defaults to using all levels.

*pixel*:
   If *True*, measure distance in pixel space, if not, measure
   distance in axes space.  Defaults to *True*.