Esempio n. 1
0
def plot_power_time(tfrs,
                    picks,
                    frequency,
                    pick_names=[],
                    event_names=[],
                    ncol=3):
    # find the frequency index
    nplots = len(picks) + 1  # last will be legend
    nrow, ncol = helpers.nrow_ncol(nplots, ncol)
    gs = gridspec.GridSpec(nrow, ncol)
    fig = plt.figure()
    for i, pick in enumerate(picks):
        ax = fig.add_subplot(gs[i])
        for n, event_tfr in enumerate(tfrs):
            ax.plot(event_tfr.times,
                    event_tfr.data[pick, frequency, :],
                    label=event_names[n])
            ax.legend([create_pick_name(i, pick_names)])
    # adds legend
    ax = fig.add_subplot(gs[nplots - 1])
    for n, _ in enumerate(tfrs):
        ax.plot([0], label=event_names[n])
        handles, labels = ax.get_legend_handles_labels()
    plt.legend(handles, labels)
    plt.show()
Esempio n. 2
0
def custom_box_layout(ch_names, ncol=6):
    # Creates boundaries of the 0-1 box, will be
    box = (-0.1, 1.1, -0.1, 1.1)
    # just puts the channel names to strings
    nrow, ncol = helpers.nrow_ncol(len(ch_names), ncol=ncol)
    x, y = np.mgrid[0:1:(1 / ncol), 0:1:(1 / nrow)]
    xy = np.vstack([x.ravel(), y.ravel()]).T
    w, h = [1 / (1.1 * ncol), 1 / (1.1 * nrow)]
    w, h = [np.tile(i, xy.shape[0]) for i in [w, h]]
    pos = np.hstack([xy, w[:, None], h[:, None]])
    # removes redundat column
    pos = pos[:len(ch_names)]
    ch_indices = range(len(ch_names))
    box_layout = Layout(box, pos, ch_names, ch_indices, 'box')
    return (box_layout)
Esempio n. 3
0
def plot_power_time_average(tfrs,
                            picks,
                            frequency,
                            channel_name=[],
                            event_names=[],
                            ncol=3):
    # find the frequency index
    nplots = len(picks) + 1  # last will be legend
    nrow, ncol = helpers.nrow_ncol(nplots, ncol)
    plt.figure()
    ax = plt.axes()
    for n, event_tfr in enumerate(tfrs):
        data = event_tfr.data[picks, frequency, :]
        data = np.average(data, 0).squeeze()
        ax.plot(event_tfr.times, data, label=event_names[n])
    ax.legend(channel_name)
    plt.legend()
    plt.show()
Esempio n. 4
0
def plot_epochs_power(epochs, frequency, picks=None):
    epochsTFR = epochs.copy()
    if not isinstance(epochsTFR, tfr.EpochsTFR):
        print('Not Epochs TFR object')
        return
    if picks is not None:
        epochsTFR.pick_channels(picks)
    # recalculates to seconds from sampling freq
    n_epochs = epochsTFR.data.shape[0]
    x, y = np.meshgrid(epochsTFR.times, range(n_epochs))

    nrow, ncol = helpers.nrow_ncol(epochsTFR.data.shape[1])
    gs = gridspec.GridSpec(nrow, ncol)
    fig = plt.figure()
    for i, channel in enumerate(epochsTFR.ch_names):
        ax = fig.add_subplot(gs[i])
        # recalculates to seconds from sampling freq
        values = np.array(epochsTFR.data[:, i, frequency, :])
        im = ax.pcolormesh(x, y, values)
        ax.set_title(epochsTFR.ch_names[i])
    fig.subplots_adjust(right=0.8)
    fig.colorbar(im)
    plt.show()
Esempio n. 5
0
def plot_wilcox_box(wilcox_table,
                    sampling_frequency,
                    cutout=0.05,
                    freqs=[],
                    picks=[],
                    pick_names=[]):
    if len(freqs) == 0:
        freqs = range(len(wilcox_table[0]) + 1)
    if len(picks) == 0:
        picks = range(len(wilcox_table))
    # find the frequency index
    times = range(len(wilcox_table[0][0]))
    times = [time / sampling_frequency for time in times]
    x, y = np.meshgrid(times, freqs)

    nrow, ncol = helpers.nrow_ncol(len(picks))
    gs = gridspec.GridSpec(nrow, ncol)
    fig = plt.figure()
    # pick the desired colormap, sensible levels, and define a normalization
    # instance which takes data values and translates those into levels.
    cmap, norm = mneplothelp.significance_plot_norms(cutout)
    for i, channel in enumerate(picks):
        ax = fig.add_subplot(gs[i])
        #recalculates to seconds from sampling freq
        p_values = np.array(wilcox_table[i])
        p_values[p_values > cutout] = 1
        p_values[p_values < -cutout] = -1
        p_values[(p_values > 0) & (
            p_values <= cutout)] = cutout - 0.0001  #because of how >< works
        p_values[(p_values < 0) & (p_values >= -cutout)] = -cutout + 0.0001
        im = ax.pcolormesh(x, y, p_values, cmap=cmap, norm=norm)
        ax.set_title([mnehelp.create_pick_name(i, pick_names)])
    fig.subplots_adjust(right=0.8)
    cbar_ax = fig.add_axes([0.85, 0.15, 0.05, 0.7])
    fig.colorbar(im, cax=cbar_ax)
    plt.show()