Add a pin at the maximum value of a data series (sort of)

def add_custom_pin(plot, x, y, label, distance='3ex'):
    """Add a pin at the maximum value of a data series (sort of)"""

    # only use the second quarter, for cosmetic reasons
    q = int(0.25 * len(y))
    y = y[q:2*q]
    max_index = q + np.argmax(y)
    max_x = x[max_index]
    plot.add_pin(label, x=max_x, location='above', use_arrow=True,
                 style='pin distance=%s' % distance)