'Find a good place to plot a label (relatively flat
part of the contour).'

def locate_label(self, linecontour, labelwidth):

    nsize = len(linecontour)
    if (labelwidth > 1):
        xsize = int(np.ceil((nsize / labelwidth)))
    else:
        xsize = 1
    if (xsize == 1):
        ysize = nsize
    else:
        ysize = int(labelwidth)
    XX = np.resize(linecontour[:, 0], (xsize, ysize))
    YY = np.resize(linecontour[:, 1], (xsize, ysize))
    yfirst = YY[:, 0].reshape(xsize, 1)
    ylast = YY[:, (-1)].reshape(xsize, 1)
    xfirst = XX[:, 0].reshape(xsize, 1)
    xlast = XX[:, (-1)].reshape(xsize, 1)
    s = (((yfirst - YY) * (xlast - xfirst)) - ((xfirst - XX) * (ylast - yfirst)))
    L = np.sqrt((((xlast - xfirst) ** 2) + ((ylast - yfirst) ** 2))).ravel()
    with np.errstate(divide=u'ignore', invalid=u'ignore'):
        dist = np.add.reduce([(abs(s)[i] / L[i]) for i in range(xsize)], (-1))
    (x, y, ind) = self.get_label_coords(dist, XX, YY, ysize, labelwidth)
    lc = [tuple(l) for l in linecontour]
    dind = lc.index((x, y))
    return (x, y, dind)
