def rescale(ys, ymin=0, ymax=1):
    """ Return rescaling parameters given a list of values,
    and a new minimum and maximum. """

    bounds = min(ys), max(ys)
    ys_range = bounds[1] - bounds[0]
    new_range = ymax - ymin

    ys_mid = sum(bounds)*.5
    new_mid = sum([ymax, ymin])*.5
    scale = float(new_range) / ys_range

    return scale, ys_mid, new_mid