def rebin_vis(arr, nb1, nb2):
    """Rebins a 2-D array for plotting.

    Excess bins along either axis are discarded.

    Parameters
    ----------
    arr : ndarray
        The two-dimensional array to rebin.
    nb1 : int
        The number of bins to rebin by along axis 0.
    nb2 : int
        The number of bins to rebin by along the axis 1.

    Returns
    -------
    arr: ndarray
        The rebinned array.
    """
    arr = arr[:arr.shape[0]//nb1*nb1, :arr.shape[1]//nb2*nb2].reshape(
        -1, nb1, arr.shape[1]).mean(1)
    arr = arr.reshape(arr.shape[0], -1, nb2).mean(-1)
    return arr