Exemple #1
0
    def plot_means(self, save=False, ax=None, label_x=True):

        redgreen = lambda nc: sns.blend_palette(["#c0392b", "#27ae60"], n_colors=nc)
        sns.set(style='white', font_scale=1.5)
        if not hasattr(self, 'bold_mag'):
            self.make_bold_dfs()
        if ax is None:
            f, ax = plt.subplots(1, figsize=(5, 5))

        titl = describe_model(self.depends_on)
        df = self.bold_mag.copy()
        df.ix[(df.choice == 'go') & (df.cond <= 50), 'cond'] = 40
        df.ix[(df.choice == 'nogo') & (df.cond >= 50), 'cond'] = 60
        sns.barplot('cond', 'csum', data=df, order=np.sort(df.cond.unique()), palette=redgreen(6), ax=ax)

        mu = df.groupby(['choice', 'cond']).mean()['csum']
        ax.set_ylim(mu.min() * .55, mu.max() * 1.15)
        ax.set_xticklabels([])
        ax.set_xlabel('')
        if label_x:
            ax.set_xlabel('pGo', fontsize=24)
            ax.set_xticklabels(np.sort(df.cond.unique()), fontsize=22)
        ax.set_ylabel('$\Sigma \\theta_{G}$', fontsize=30)
        ax.set_yticklabels([])
        sns.despine()
        plt.tight_layout()
        if save:
            plt.savefig('_'.join([titl, self.decay, 'means.png']), dpi=300)
            plt.savefig(
                '_'.join([titl, self.decay, 'means.svg']), format='svg', rasterized=True)
        return ax
Exemple #2
0
    def plot_traces(self, style='HL', ax=None, label_x=True, save=False):

        cpals = get_cpals()
        sns.set(style='white', font_scale=1.5)
        if ax is None:
            f, ax = plt.subplots(1, figsize=(5, 5))

        tr = self.onset
        titl = describe_model(self.depends_on)
        if style not in ['HL', 'HML']:
            gmu = [ggt.mean(axis=1) for ggt in self.go_traces]
            nmu = [ngt.mean(axis=1) for ngt in self.ng_traces]
        else:
            go_counts = [self.go_traces[i].shape[1]
                         for i in range(len(self.go_traces))]
            ng_counts = [self.ng_traces[i].shape[1]
                         for i in range(len(self.ng_traces))]
            go_lo_ri = randint(0, high=go_counts[0])
            go_hi_ri = randint(0, high=go_counts[-1])
            ng_lo_ri = randint(0, high=ng_counts[0])
            ng_hi_ri = randint(0, high=ng_counts[-1])
            ng_hi_ri = np.argmin(self.ng_traces[-1].iloc[-1, :])

            glow = self.go_traces[0].iloc[:, go_lo_ri].dropna().values
            #pd.concat(self.go_traces[1:3], axis=1).iloc[:,0]
            ghi = self.go_traces[-1].iloc[:, go_hi_ri].dropna().values

            nglow = self.ng_traces[0].iloc[:, ng_lo_ri].dropna().values
            nghi = self.ng_traces[-1].iloc[:, ng_hi_ri].dropna().values

            # return nglow, nghi
            gmu = [glow, ghi]
            nmu = [nglow, nghi]
            tr = [tr[0], tr[-1]]
            gc = ["#40ac5b", '#10ac1d']
            nc = ['#dc3c3c', '#d61b1b']
        #gc = cpals['gpal'](len(gmu))
        #nc = cpals['rpal'](len(nmu))

        gx = [tr[i] + np.arange(len(gmu[i])) * self.dt for i in range(len(gmu))]
        nx = [tr[i] + np.arange(len(nmu[i])) * self.dt for i in range(len(nmu))]
        ls = ['-', '-']
        for i in range(len(gmu)):
            ax.plot(gx[i], gmu[i], linestyle=ls[i], lw=1, color=gc[i])
            ax.fill_between(gx[i], gmu[i], y2=0, lw=1, color=gc[i], alpha=.25)
        for i in range(len(nmu)):
            ax.plot(nx[i], nmu[i], linestyle=ls[i], lw=1, color=nc[i])
            ax.fill_between(nx[i], nmu[i], y2=0, lw=1, color=nc[i], alpha=.25)

        ax.set_ylim(0, self.p['a'].max() * 1.01)
        ax.set_xlim(gx[-1].min() * .98, nx[0].max() * 1.05)
        if label_x:
            ax.set_xlabel('Time', fontsize=26)
        ax.set_xticklabels([])
        ax.set_yticklabels([])
        ax.set_ylabel('$\\theta_{G}$', fontsize=30)

        sns.despine()
        plt.tight_layout()
        if save:
            plt.savefig('_'.join([titl, self.decay, 'traces.png']), dpi=300)
            plt.savefig('_'.join([titl, self.decay, 'traces.svg']), format='svg', rasterized=True)
        return ax