def plot_connectivity_spectrum(a, fs=2, freq_range=(-np.inf, np.inf), diagonal=0, border=False, fig=None):

    a = np.atleast_3d(a)
    if a.ndim == 3:
        [_, m, f] = a.shape
        l = 0
    else:
        [l, _, m, f] = a.shape
    freq = np.linspace(0, fs / 2, f)

    lowest, highest = np.inf, -np.inf
    left = max(freq_range[0], freq[0])
    right = min(freq_range[1], freq[-1])

    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))
            if l == 0:
                ax.plot(freq, a[i, j, :])
                lowest = min(lowest, np.min(a[i, j, :]))
                highest = max(highest, np.max(a[i, j, :]))
            elif l == 1:
                ax.fill_between(freq, 0, a[0, i, j, :], facecolor=[0.25, 0.25, 0.25], alpha=0.25)
                lowest = min(lowest, np.min(a[0, i, j, :]))
                highest = max(highest, np.max(a[0, i, j, :]))
            else:
                baseline,  = ax.plot(freq, a[0, i, j, :])
                ax.fill_between(freq, a[1, i, j, :], a[2, i, j, :], facecolor=baseline.get_color(), alpha=0.25)
                lowest = min(lowest, np.min(a[:, i, j, :]))
                highest = max(highest, np.max(a[:, i, j, :]))

    for i, j, ax in axes:
        ax.xaxis.set_major_locator(MaxNLocator(max(1, 7 - m)))
        ax.yaxis.set_major_locator(MaxNLocator(max(1, 7 - m)))
        al = ax.get_ylim()
        ax.set_ylim(min(al[0], lowest), max(al[1], highest))
        ax.set_xlim(left, right)

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

        if i == 0:
            ax.xaxis.tick_top()
        if i == m-1:
            ax.xaxis.tick_bottom()

        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
Draw connectivity plots.
dataset/ETHPy150Open scot-dev/scot/scot/plotting.py/plot_connectivity_spectrum