def _compscale(data):
    """
    Automatically computes a scaling for the wavefunctions in the plot.

    Args:
        data (dict): The data neccesarry for computing the scale factor. Needs
            to contain 'wfuncs' and 'energies'.

    Returns:
        scale (float): The computed scale.

    """
    wfuncs = data['wfuncs'].T
    energies = data['energies']
    scale = 1e6  # choose an arbitray large number

    for index in range(len(energies) - 1):
        new_scale = (energies[index + 1] - energies[index]) / (
            abs(min(wfuncs[index + 1])) + max(wfuncs[index]))
        if new_scale < scale:
            scale = new_scale

    return scale