def _label(label_fmt, value, fac_name=None):
    """Return the appropriate label for a factor.

    :param label_fmt: The format string, or a function that returns the label.
    :param value: The value of the faceting variable.
    :param fac_name: The (optional) name of the faceting variable, used in
        error messages.
    :raises ValueError: if ``label_fmt`` is not a format string or a function.
    """
    if hasattr(label_fmt, 'format'):
        return label_fmt.format(value)
    elif callable(label_fmt):
        return label_fmt(value)
    else:
        if fac_name is None:
            msg = "invalid `label_fmt`: {}".format(label_fmt)
        else:
            msg = "invalid `label_fmt` for {}: {}".format(fac_name, label_fmt)
        raise ValueError(msg)