Beispiel #1
0
def plot_taskaxes(plot, yax, p_vc, basecolor):
    abscohs = []
    for choice, coh, context in p_vc:
        abscohs.append(abs(coh))
    abscohs = sorted(list(set(abscohs)))

    #-------------------------------------------------------------------------------------
    # Subtract mean
    #-------------------------------------------------------------------------------------

    p = p_vc.values()[0]
    Xchoice = np.zeros_like(p[CHOICE])
    Xmotion = np.zeros_like(p[MOTION])
    Xcolour = np.zeros_like(p[COLOUR])

    for p in p_vc.values():
        Xchoice += p[CHOICE]
        Xmotion += p[MOTION]
        Xcolour += p[COLOUR]
    mean_choice = Xchoice / len(p_vc)
    mean_motion = Xmotion / len(p_vc)
    mean_colour = Xcolour / len(p_vc)

    for cond, p in p_vc.items():
        p[CHOICE] -= mean_choice
        p[MOTION] -= mean_motion
        p[COLOUR] -= mean_colour

    #-------------------------------------------------------------------------------------

    xall = []
    yall = []
    for cond, p in p_vc.items():
        idx = abscohs.index(abs(cond[1]))
        if idx == 0:
            color = apply_alpha(basecolor, 0.4)
        elif idx == 1:
            color = apply_alpha(basecolor, 0.7)
        else:
            color = apply_alpha(basecolor, 1)

        if cond[1] > 0:
            prop = dict(mfc=color, mec=color, ms=2.5, mew=0.5)
        else:
            prop = dict(mfc='w', mec=color, ms=2.5, mew=0.5)

        plot.plot(p[CHOICE], p[yax], '-', color=color, lw=0.75)
        plot.plot(p[CHOICE][::2], p[yax][::2], 'o', color=color, **prop)

        xall.append(p[CHOICE])
        yall.append(p[yax])

    if yax == MOTION:
        plot.ylabel('Motion')
    elif yax == COLOUR:
        plot.ylabel('Color')

    return np.concatenate(xall), np.concatenate(yall)
def plot_taskaxes(plot, yax, p_vc, basecolor):
    abscohs = []
    for choice, coh, context in p_vc:
        abscohs.append(abs(coh))
    abscohs = sorted(list(set(abscohs)))

    #-------------------------------------------------------------------------------------
    # Subtract mean
    #-------------------------------------------------------------------------------------

    p = p_vc.values()[0]
    Xchoice = np.zeros_like(p[CHOICE])
    Xmotion = np.zeros_like(p[MOTION])
    Xcolour = np.zeros_like(p[COLOUR])

    for p in p_vc.values():
        Xchoice += p[CHOICE]
        Xmotion += p[MOTION]
        Xcolour += p[COLOUR]
    mean_choice = Xchoice/len(p_vc)
    mean_motion = Xmotion/len(p_vc)
    mean_colour = Xcolour/len(p_vc)

    for cond, p in p_vc.items():
        p[CHOICE] -= mean_choice
        p[MOTION] -= mean_motion
        p[COLOUR] -= mean_colour

    #-------------------------------------------------------------------------------------

    xall = []
    yall = []
    for cond, p in p_vc.items():
        idx = abscohs.index(abs(cond[1]))
        if idx == 0:
            color = apply_alpha(basecolor, 0.4)
        elif idx == 1:
            color = apply_alpha(basecolor, 0.7)
        else:
            color = apply_alpha(basecolor, 1)

        if cond[1] > 0:
            prop = dict(mfc=color, mec=color, ms=2.5, mew=0.5)
        else:
            prop = dict(mfc='w', mec=color, ms=2.5, mew=0.5)

        plot.plot(p[CHOICE],      p[yax],      '-', color=color, lw=0.75)
        plot.plot(p[CHOICE][::2], p[yax][::2], 'o', color=color, **prop)

        xall.append(p[CHOICE])
        yall.append(p[yax])

    if yax == MOTION:
        plot.ylabel('Motion')
    elif yax == COLOUR:
        plot.ylabel('Color')

    return np.concatenate(xall), np.concatenate(yall)
ms_empty  = 2.5

mew_filled = 0.5
mew_empty  = 0.5

y  = 1.2
dx = 0.08
dy = 0.06

fontsize = 4.75

for context, plot, basecolor in zip(['Motion', 'Color'],
                                    [plots['c1'], plots['c3']],
                                    ['k', Figure.colors('darkblue')]):
    transform = plot.ax.transAxes
    colors    = [apply_alpha(basecolor, alpha) for alpha in [0.4, 0.7, 1]]
    for i in xrange(3):
        plot.plot(0.5+(i+0.5)*dx, y, 'o', mfc=colors[i], mec=colors[i],
                  ms=ms_filled, mew=mew_filled, transform=transform)
        plot.plot(0.5-(i+0.5)*dx, y, 'o', mfc='none', mec=colors[i],
                  ms=ms_empty, mew=mew_empty, transform=transform)

    # Strength label
    plot.text(0.5, y+dy, 'Weak', ha='center', va='bottom', fontsize=fontsize,
              color=colors[0], transform=transform)
    plot.text(0.5+2.5*dx, y+dy, 'Strong', ha='center', va='bottom', fontsize=fontsize,
              color=colors[-1], transform=transform)
    plot.text(0.5-2.5*dx, y+dy, 'Strong', ha='center', va='bottom', fontsize=fontsize,
              color=colors[-1], transform=transform)

    if context == 'Motion':
Beispiel #4
0
def plot_unit(unit,
              sortedfile,
              plots,
              t0=0,
              tmin=-np.inf,
              tmax=np.inf,
              **kwargs):
    # Load sorted trials
    with open(sortedfile, 'rb') as f:
        t, sorted_trials = pickle.load(f)

    #-------------------------------------------------------------------------------------
    # Labels
    #-------------------------------------------------------------------------------------

    # Unit no.
    fontsize = kwargs.get('unit_fontsize', 7)
    plots['choice'].text_upper_center('Unit ' + str(unit),
                                      dy=0.07,
                                      fontsize=fontsize)

    # Sort-by
    if kwargs.get('sortby_fontsize') is not None:
        fontsize = kwargs['sortby_fontsize']
        labels = {
            'choice': 'choice',
            'motion_choice': 'motion \& choice',
            'colour_choice': 'color \& choice',
            'context_choice': 'context \& choice'
        }
        for k, label in labels.items():
            plots[k].ylabel(label)

    #-------------------------------------------------------------------------------------
    # Setup
    #-------------------------------------------------------------------------------------

    # Duration to plot
    w, = np.where((tmin <= t) & (t <= tmax))
    t = t - t0

    # Linestyle
    def get_linestyle(choice):
        if choice == +1:
            return '-'
        return '--'

    # Line width
    lw = kwargs.get('lw', 1)

    # For setting axis limits
    yall = []

    #-------------------------------------------------------------------------------------
    # Choice
    #-------------------------------------------------------------------------------------

    plot = plots['choice']
    condition_averaged = sorted_trials['choice']

    for (choice, ), r in condition_averaged.items():
        ls = get_linestyle(choice)
        plot.plot(t[w], r[unit, w], ls, color=Figure.colors('red'), lw=lw)
        yall.append(r[unit, w])
    plot.xlim(t[w][0], t[w][-1])
    plot.xticks([t[w][0], 0, t[w][-1]])

    #-------------------------------------------------------------------------------------
    # Motion & choice
    #-------------------------------------------------------------------------------------

    plot = plots['motion_choice']
    condition_averaged = sorted_trials['motion_choice']

    abscohs = []
    for (choice, coh, context) in condition_averaged:
        abscohs.append(abs(coh))
    abscohs = sorted(list(set(abscohs)))

    for (choice, coh, context), r in condition_averaged.items():
        if context != 'm':
            continue

        ls = get_linestyle(choice)

        idx = abscohs.index(abs(coh))
        basecolor = 'k'
        if idx == 0:
            color = apply_alpha(basecolor, 0.4)
        elif idx == 1:
            color = apply_alpha(basecolor, 0.7)
        else:
            color = apply_alpha(basecolor, 1)

        plot.plot(t[w], r[unit, w], ls, color=color, lw=lw)
        yall.append(r[unit, w])
    plot.xlim(t[w][0], t[w][-1])
    plot.xticks([t[w][0], 0, t[w][-1]])

    #-------------------------------------------------------------------------------------
    # Colour & choice
    #-------------------------------------------------------------------------------------

    plot = plots['colour_choice']
    condition_averaged = sorted_trials['colour_choice']

    abscohs = []
    for (choice, coh, context) in condition_averaged:
        abscohs.append(abs(coh))
    abscohs = sorted(list(set(abscohs)))

    for (choice, coh, context), r in condition_averaged.items():
        if context != 'c':
            continue

        ls = get_linestyle(choice)

        idx = abscohs.index(abs(coh))
        basecolor = Figure.colors('darkblue')
        if idx == 0:
            color = apply_alpha(basecolor, 0.4)
        elif idx == 1:
            color = apply_alpha(basecolor, 0.7)
        else:
            color = apply_alpha(basecolor, 1)

        plot.plot(t[w], r[unit, w], ls, color=color, lw=lw)
        yall.append(r[unit, w])
    plot.xlim(t[w][0], t[w][-1])
    plot.xticks([t[w][0], 0, t[w][-1]])

    #-------------------------------------------------------------------------------------
    # Context & choice
    #-------------------------------------------------------------------------------------

    plot = plots['context_choice']
    condition_averaged = sorted_trials['context_choice']

    for (choice, context), r in condition_averaged.items():
        ls = get_linestyle(choice)

        if context == 'm':
            color = 'k'
        else:
            color = Figure.colors('darkblue')

        plot.plot(t[w], r[unit, w], ls, color=color, lw=lw)
        yall.append(r[unit, w])
    plot.xlim(t[w][0], t[w][-1])
    plot.xticks([t[w][0], 0, t[w][-1]])

    return yall
Beispiel #5
0
ms_empty = 2.5

mew_filled = 0.5
mew_empty = 0.5

y = 1.2
dx = 0.08
dy = 0.06

fontsize = 4.75

for context, plot, basecolor in zip(['Motion', 'Color'],
                                    [plots['c1'], plots['c3']],
                                    ['k', Figure.colors('darkblue')]):
    transform = plot.ax.transAxes
    colors = [apply_alpha(basecolor, alpha) for alpha in [0.4, 0.7, 1]]
    for i in xrange(3):
        plot.plot(0.5 + (i + 0.5) * dx,
                  y,
                  'o',
                  mfc=colors[i],
                  mec=colors[i],
                  ms=ms_filled,
                  mew=mew_filled,
                  transform=transform)
        plot.plot(0.5 - (i + 0.5) * dx,
                  y,
                  'o',
                  mfc='none',
                  mec=colors[i],
                  ms=ms_empty,
def plot_unit(unit, sortedfile, plots, t0=0, tmin=-np.inf, tmax=np.inf, **kwargs):
    # Load sorted trials
    with open(sortedfile) as f:
        t, sorted_trials = pickle.load(f)

    #-------------------------------------------------------------------------------------
    # Labels
    #-------------------------------------------------------------------------------------

    # Unit no.
    fontsize = kwargs.get('unit_fontsize', 7)
    plots['choice'].text_upper_center('Unit '+str(unit), dy=0.07, fontsize=fontsize)

    # Sort-by
    if kwargs.get('sortby_fontsize') is not None:
        fontsize = kwargs['sortby_fontsize']
        labels = {
            'choice':         'choice',
            'motion_choice':  'motion \& choice',
            'colour_choice':  'color \& choice',
            'context_choice': 'context \& choice'
            }
        for k , label in labels.items():
            plots[k].ylabel(label)

    #-------------------------------------------------------------------------------------
    # Setup
    #-------------------------------------------------------------------------------------

    # Duration to plot
    w, = np.where((tmin <= t) & (t <= tmax))
    t  = t - t0

    # Linestyle
    def get_linestyle(choice):
        if choice == +1:
            return '-'
        return '--'

    # Line width
    lw = kwargs.get('lw', 1)

    # For setting axis limits
    yall = []

    #-------------------------------------------------------------------------------------
    # Choice
    #-------------------------------------------------------------------------------------

    plot = plots['choice']
    condition_averaged = sorted_trials['choice']

    for (choice,), r in condition_averaged.items():
        ls = get_linestyle(choice)
        plot.plot(t[w], r[unit,w], ls, color=Figure.colors('red'), lw=lw)
        yall.append(r[unit,w])
    plot.xlim(t[w][0], t[w][-1])
    plot.xticks([t[w][0], 0, t[w][-1]])

    #-------------------------------------------------------------------------------------
    # Motion & choice
    #-------------------------------------------------------------------------------------

    plot = plots['motion_choice']
    condition_averaged = sorted_trials['motion_choice']

    abscohs = []
    for (choice, coh, context) in condition_averaged:
        abscohs.append(abs(coh))
    abscohs = sorted(list(set(abscohs)))

    for (choice, coh, context), r in condition_averaged.items():
        if context != 'm':
            continue

        ls = get_linestyle(choice)

        idx = abscohs.index(abs(coh))
        basecolor = 'k'
        if idx == 0:
            color = apply_alpha(basecolor, 0.4)
        elif idx == 1:
            color = apply_alpha(basecolor, 0.7)
        else:
            color = apply_alpha(basecolor, 1)

        plot.plot(t[w], r[unit,w], ls, color=color, lw=lw)
        yall.append(r[unit,w])
    plot.xlim(t[w][0], t[w][-1])
    plot.xticks([t[w][0], 0, t[w][-1]])

    #-------------------------------------------------------------------------------------
    # Colour & choice
    #-------------------------------------------------------------------------------------

    plot = plots['colour_choice']
    condition_averaged = sorted_trials['colour_choice']

    abscohs = []
    for (choice, coh, context) in condition_averaged:
        abscohs.append(abs(coh))
    abscohs = sorted(list(set(abscohs)))

    for (choice, coh, context), r in condition_averaged.items():
        if context != 'c':
            continue

        ls = get_linestyle(choice)

        idx = abscohs.index(abs(coh))
        basecolor = Figure.colors('darkblue')
        if idx == 0:
            color = apply_alpha(basecolor, 0.4)
        elif idx == 1:
            color = apply_alpha(basecolor, 0.7)
        else:
            color = apply_alpha(basecolor, 1)

        plot.plot(t[w], r[unit,w], ls, color=color, lw=lw)
        yall.append(r[unit,w])
    plot.xlim(t[w][0], t[w][-1])
    plot.xticks([t[w][0], 0, t[w][-1]])

    #-------------------------------------------------------------------------------------
    # Context & choice
    #-------------------------------------------------------------------------------------

    plot = plots['context_choice']
    condition_averaged = sorted_trials['context_choice']

    for (choice, context), r in condition_averaged.items():
        ls = get_linestyle(choice)

        if context == 'm':
            color = 'k'
        else:
            color = Figure.colors('darkblue')

        plot.plot(t[w], r[unit,w], ls, color=color, lw=lw)
        yall.append(r[unit,w])
    plot.xlim(t[w][0], t[w][-1])
    plot.xticks([t[w][0], 0, t[w][-1]])

    return yall