Plot significance.

    Significance is drawn as a background image where dark vertical stripes indicate freuquencies where a evaluates to
    True.

    Parameters
    ----------
    a : array, shape (n_channels, n_channels, n_fft), dtype bool
        Significance
    fs : float
        Sampling frequency
    freq_range : (float, float)
        Frequency range to plot
    diagonal : {-1, 0, 1}
        If diagonal == -1 nothing is plotted on the diagonal (a[i,i,:] are not plotted),
        if diagonal == 0, a is plotted on the diagonal too (all a[i,i,:] are plotted),
        if diagonal == 1, a is plotted on the diagonal only (only a[i,i,:] are plotted)
    border : bool
        If border == true the leftmost column and the topmost row are left blank
    fig : Figure object, optional
        Figure to plot into. If set to `None`, a new figure is created.

    Returns
    -------
    fig : Figure object
        The figure into which was plotted.

def plot_connectivity_significance(s, fs=2, freq_range=(-np.inf, np.inf), diagonal=0, border=False, fig=None):
    """Plot significance.

    Significance is drawn as a background image where dark vertical stripes indicate freuquencies where a evaluates to
    True.

    Parameters
    ----------
    a : array, shape (n_channels, n_channels, n_fft), dtype bool
        Significance
    fs : float
        Sampling frequency
    freq_range : (float, float)
        Frequency range to plot
    diagonal : {-1, 0, 1}
        If diagonal == -1 nothing is plotted on the diagonal (a[i,i,:] are not plotted),
        if diagonal == 0, a is plotted on the diagonal too (all a[i,i,:] are plotted),
        if diagonal == 1, a is plotted on the diagonal only (only a[i,i,:] are plotted)
    border : bool
        If border == true the leftmost column and the topmost row are left blank
    fig : Figure object, optional
        Figure to plot into. If set to `None`, a new figure is created.

    Returns
    -------
    fig : Figure object
        The figure into which was plotted.
    """

    a = np.atleast_3d(s)
    [_, m, f] = a.shape
    freq = np.linspace(0, fs / 2, f)

    left = max(freq_range[0], freq[0])
    right = min(freq_range[1], freq[-1])

    imext = (freq[0], freq[-1], -1e25, 1e25)

    if fig is None:
        fig = new_figure()

    axes = []
    for i in range(m):
        if diagonal == 1:
            jrange = [i]
        elif diagonal == 0:
            jrange = range(m)
        else:
            jrange = [j for j in range(m) if j != i]
        for j in jrange:
            if border:
                ax = fig.add_subplot(m+1, m+1, j + (i+1) * (m+1) + 2)
            else:
                ax = fig.add_subplot(m, m, j + i * m + 1)
            axes.append((i, j, ax))
            ax.imshow(s[i, j, np.newaxis], vmin=0, vmax=2, cmap='binary', aspect='auto', extent=imext, zorder=-999)

            ax.xaxis.set_major_locator(MaxNLocator(max(1, 7 - m)))
            ax.yaxis.set_major_locator(MaxNLocator(max(1, 7 - m)))
            ax.set_xlim(left, right)

            if 0 < i < m - 1:
                ax.set_xticks([])
            if 0 < j < m - 1:
                ax.set_yticks([])

            if j == 0:
                ax.yaxis.tick_left()
            if j == m-1:
                ax.yaxis.tick_right()

    _plot_labels(fig,
                 {'x': 0.5, 'y': 0.025, 's': 'frequency (Hz)', 'horizontalalignment': 'center'},
                 {'x': 0.05, 'y': 0.5, 's': 'magnitude', 'horizontalalignment': 'center', 'rotation': 'vertical'})

    return fig