def set_lim(lim, get_lim_f, set_lim_f):
    """Set x or y limitis of the plot

    lim can be a tuple containing the limits or the string "default"
    or "range".  "default" does nothing and uses matplotlib default.
    "range" extends the current margin by 10%.  This is useful since
    the default xlim and ylim of the plots sometimes make it harder to
    see data that is just in the margin.

    """
    if lim == 'default':
        return
    if lim == 'range':
        cur_lim = get_lim_f()
        lim = cur_lim[0] - 0.1 * (cur_lim[1] - cur_lim[0]), cur_lim[1
            ] + 0.1 * (cur_lim[1] - cur_lim[0])
    set_lim_f(lim[0], lim[1])
