def handle_reference_points(ref, ax, fvals):
    """
    Handle reference points.

    Parameters
    ----------

    ref: list, optional
        List of reference points for optimization results, containing et
        least a function value fval

    ax: matplotlib.Axes, optional
        Axes object to use.
    """
    if len(ref) > 0:
        par_indices = []
        for i_plot, fval in enumerate(fvals):
            if fval is not None:
                par_indices.append(i_plot)
        for i_par, i_ax in enumerate(ax):
            for i_ref in ref:
                current_x = i_ref['x'][par_indices[i_par]]
                i_ax.plot([current_x, current_x], [0.0, 1.0], color=i_ref.
                    color, label=i_ref.legend)
            if i_ref.legend is not None:
                i_ax.legend()
    return ax
