def PC_traj(df, rep, file_type):
    """this function groups by drug an plots the trajectories through PC space"""
    #scale the PCs
    xscale = 1 / (np.max(df['PC_1']) - np.min(df['PC_1']))
    yscale = 1 / (np.max(df['PC_2']) - np.min(df['PC_2']))
    #okay so now have a summary of each drug for each PC.
    #scale and plot the drugs across the PC1 and 2 space
    uniqueDrugs1 = np.unique(df['drug'])
    cmap = sns.choose_colorbrewer_palette(data_type='q')
    #cmap = sns.color_palette("husl", len(uniqueDrugs1)) #set colormap
    for drug in range(len(uniqueDrugs1)):
        to_plot = df['drug'] == uniqueDrugs1[drug]
        plotting1 = df[to_plot]
        ax = plt.plot(plotting1['PC_1']*xscale, plotting1['PC_2']*yscale, \
                      linewidth =2, color = cmap[drug], marker = 'o', \
                      label = uniqueDrugs1[drug])
    plt.xlim(-1, 1)
    plt.ylim(-1, 1)
    plt.legend(loc=2, ncol=3, frameon=True)
    plt.xlabel('PC_1')
    plt.ylabel('PC_2')
    plt.savefig(os.path.join(directory[0:-7], 'Figures',
                             rep + '_PCtraj.' + file_type),
                dpi=200)
    plt.show()
def PC12_plots(df, dose, rep, file_type):
    """this makes plots that are scaled PCs"""
    sns.set_style('whitegrid')
    cmap = sns.choose_colorbrewer_palette(data_type='q')
    if dose == []:
        temp = df
    else:
        to_plot = (df['concentration'] == float(dose)
                   )  # or (df['concentration'] == float(14))
        temp = df[to_plot]
        temp = temp.append(df[df['drug'] == 'DMSO'])  #add on DMSO controls
        temp = temp.append(df[df['drug'] == 'No_Compound'])
    xs = temp['PC_1']
    ys = temp['PC_2']
    scalex = 1 / (xs.max() - xs.min())
    scaley = 1 / (ys.max() - ys.min())
    temp['PC_1'] = temp['PC_1'].replace(temp['PC_1'].values, xs * scalex)
    temp['PC_2'] = temp['PC_2'].replace(temp['PC_2'].values, ys * scaley)
    f = plt.figure
    f = sns.lmplot(x='PC_1', y='PC_2', data=temp, hue='drug', fit_reg=False)
    #add in arrow plot
    #f = plt.arrow(0,0, PC_feats['PC_1'].iloc[PC_top['PC_1'].index[0]],\
    #             PC_feats['PC_2'].iloc[PC_top['PC_1'].index[i]], \
    #            color = 'm', alpha = 1, linewidth = 2)

    plt.xlim(-1, 1)
    plt.ylim(-1, 1)
    plt.title('concentration = ' + str(dose))
    plt.savefig (os.path.join(directory[0:-7], 'Figures', rep + '_'\
                              + str(dose) + '_PC12_norm.' + file_type), dpi = 200)
Exemplo n.º 3
0
def plot_ens_mean(ax, revash, time, enslist, level=1):
    m2 = ens_mean(revash, time, enslist, level=level)
    cmap = sns.choose_colorbrewer_palette('colorblind', as_cmap=True)
    cb2 = ax.contourf(m2.longitude, m2.latitude, m2, cmap=cmap)
    plt.colorbar(cb2)
    plt.tight_layout()
    ax = plt.gca()
    return ax
def swarms(rep1, feature1):
    cmap = sns.choose_colorbrewer_palette(data_type='q')
    sns.swarmplot(x='drug', y=feature1, data=features3[rep1], \
                      hue = 'concentration', palette = cmap)
    plt.xticks(rotation=45)
    plt.savefig(os.path.join(directory[0:-7], 'Figures',
                             rep1 + feature1 + '.svg'),
                dpi=200)
Exemplo n.º 5
0
def plotATL(ax, revash, time, enslist, level, thresh=0.2, clevs=None):
    rtot = ATL(revash, time, enslist, thresh, level)
    cmap = sns.choose_colorbrewer_palette('colorblind', as_cmap=True)
    cb2 = ax.pcolormesh(rtot.longitude, rtot.latitude, rtot, cmap=cmap)
    #if not clevs:
    #    cb2 = plt.contourf(rtot.longitude, rtot.latitude, rtot, cmap=cmap)
    #if clevs:
    #    cb2 = plt.contourf(rtot.longitude, rtot.latitude, rtot, cmap=cmap,
    #                       levels=clevs)
    plt.colorbar(cb2)
    return
Exemplo n.º 6
0
def PC12_plots(df, dose, rep, directory, file_type):
    """this makes plots that are scaled PCs
    Input:
        df - dataframe containing PCs for each condition
        
        dose - dose to be plotted
        
        rep - experiment name
        
        directory - directory into which the plot will be saved
        
        file_type - tif or svg
    
    Output:
        plots of each of the conditions along PCs 1 and 2
    """
    sns.set_style('whitegrid')
    sns.palplot(sns.choose_colorbrewer_palette(data_type='q'))
    if dose == []:
        temp = df
    else:
        to_plot = (df['concentration'] == float(dose)
                   )  # or (df['concentration'] == float(14))
        temp = df[to_plot]
        temp = temp.append(df[df['drug'] == 'DMSO'])  #add on DMSO controls
        temp = temp.append(df[df['drug'] == 'No_compound'])
    xs = temp['PC_1']
    ys = temp['PC_2']
    scalex = 1 / (xs.max() - xs.min())
    scaley = 1 / (ys.max() - ys.min())
    temp['PC_1'] = temp['PC_1'].replace(temp['PC_1'].values, xs * scalex)
    temp['PC_2'] = temp['PC_2'].replace(temp['PC_2'].values, ys * scaley)
    f = plt.figure
    f = sns.lmplot(x='PC_1', y='PC_2', data=temp, hue='drug', fit_reg=False)

    plt.xlim(-1, 1)
    plt.ylim(-1, 1)
    plt.title('concentration = ' + str(dose))
    plt.savefig (os.path.join(directory[0:-7], 'Figures', rep + '_'\
                              + str(dose) + '_PC12_norm.' + file_type),\
                                bbox_inches="tight", dpi = 200)
Exemplo n.º 7
0
def ATL(revash, time, enslist, thresh=0.2, level=1):
    #import matplotlib.pyplot as plt
    #sns.set_style('whitegrid')
    source = 0
    if isinstance(level, int):
        level = [level]
    iii = 0
    for lev in level:
        r2 = revash.sel(time=time)
        r2 = r2.sel(ens=enslist)
        r2 = r2.sel(z=lev)
        r2 = r2.isel(source=source)
        # place zeros where it is below threshold
        r2 = r2.where(r2 >= thresh)
        r2 = r2.fillna(0)
        # place onces where it is above threshold
        print(r2)
        r2 = r2.where(r2 < thresh)
        r2 = r2.fillna(1)
        # ensemble members were above threshold at each location.
        r2 = r2.sum(dim=['ens'])
        if iii == 0:
            rtot = r2
            rtot.expand_dims('z')
        else:
            r2.expand_dims('z')
            rtot = xr.concat([rtot, r2], 'z')
        iii += 1
    print(rtot)
    # This gives you maximum value that were above concentration
    # at each location.
    if iii > 1: rtot = rtot.max(dim='z')
    cmap = sns.choose_colorbrewer_palette('colorblind', as_cmap=True)
    # sum up all the ones. This tells you how many
    # ensemble members were above threshold at each location.
    #r2 = r2.sum(dim=['ens'])
    return rtot
Exemplo n.º 8
0
def PC_traj(df, rep, directory, file_type):
    """this function groups by drug an plots the trajectories through PC space
    Input
        df - dataframe containing the PC values for each of the drugs
        rep - the name of the experiments
        directory - the directory to save the files into
        file_type - type of image ('tif' or 'svg' ...)
        
    Output
        Plot showing trajectory through PC space
    """
    #scale the PCs
    xscale = 1 / (np.max(df['PC_1']) - np.min(df['PC_1']))
    yscale = 1 / (np.max(df['PC_2']) - np.min(df['PC_2']))
    #okay so now have a summary of each drug for each PC.
    #scale and plot the drugs across the PC1 and 2 space
    uniqueDrugs1 = np.unique(df['drug'])
    cmap = sns.choose_colorbrewer_palette(data_type='q')
    #cmap = sns.color_palette("husl", len(uniqueDrugs1)) #set colormap
    for drug in range(len(uniqueDrugs1)):
        to_plot = df['drug'] == uniqueDrugs1[drug]
        plotting1 = df[to_plot]
        ax = plt.plot(plotting1['PC_1']*xscale, plotting1['PC_2']*yscale, \
                      linewidth =2, color = cmap[drug], marker = 'o', \
                      label = uniqueDrugs1[drug])
    plt.axis('scaled')
    plt.xlim(-1, 1)
    plt.ylim(-1, 1)
    plt.legend(loc='center left',
               bbox_to_anchor=(1, 0.5),
               ncol=1,
               frameon=True)
    plt.xlabel('PC_1')
    plt.ylabel('PC_2')
    plt.savefig(os.path.join(directory[0:-7], 'Figures', rep + '_PCtraj.' + file_type),\
                bbox_inches="tight", dpi = 200)
    plt.show()
for rep in PC_top1:
    PC.biplot(PC_top1[rep], PC_feats1[rep], 1, 2, 1, directoryA, rep, '.tif',
              uniqueDrugs)

#%% now to transform into feature space
#concanenate the eigen_vector matrix across the top 80 eigenvalues

matrix_w1 = {}
Y1 = {}
PC_df2 = {}
for rep in featuresZ1:
    matrix_w1[rep], Y1[rep], PC_df2[rep] = PC.feature_space(featuresZ1[rep], eig_pairs1[rep],\
            X_std1[rep], cut_off1[rep], x1[rep], drugA[rep], concA[rep], dateA[rep])

#set palette for plots
sns.palplot(sns.choose_colorbrewer_palette(data_type='q'))
#now make the plots
for rep in PC_df2:
    for i in [1, 10, 100, 200]:
        PC.PC12_plots(PC_df2[rep], i, rep, directoryA, 'tif')

#now can make dataframe containing means and column names to plot trajectories through PC space
PC_means1 = {}
for rep in PC_df2:
    PC_means1[rep] = PC.PC_av(PC_df2[rep], x1[rep])

sns.set_style('whitegrid')
for rep in PC_means1:
    PC.PC_traj(PC_means1[rep], rep, directoryA, 'tif')

#%% now to do the stats on the experiments
Exemplo n.º 10
0
from sklearn.metrics import accuracy_score
from sklearn.cross_validation import train_test_split
from sklearn.metrics import precision_score
from sklearn.metrics import recall_score

from sklearn import datasets, linear_model
from sklearn.naive_bayes import GaussianNB  #for Naive Bayes
from sklearn import svm  #for SVM
from sklearn.svm import SVC  #for SVM with 'rbf' kernel
from sklearn import tree  #for decision trees

# In[ ]:

# Choose color palette for the seaborn graphs for the rest of the notebook:
# Import color widget from seaborn:
sns.choose_colorbrewer_palette(data_type='sequential', as_cmap=False)
# Set color palette below:
sns.set_palette("YlGnBu", n_colors=5, desat=1, color_codes=False)

# Matplotlib color codes can be found here: http://stackoverflow.com/questions/22408237/named-colors-in-matplotlib

# Read the file and clean the data

# In[ ]:

titanic_df = pd.read_csv("../input/train.csv")
test_df = pd.read_csv("../input/test.csv")
# Preview the data
titanic_df.head()

# In[ ]:
Exemplo n.º 11
0
cm = sns.heatmap(mat.T,
                 square=True,
                 annot=False,
                 fmt='d',
                 cbar=True,
                 cmap='YlGnBu')
cm.set_xlabel("True", fontsize=50)
plt.xticks(rotation=0)
cm.set_xticklabels(labels=['low', 'medium', 'high'])
plt.yticks(rotation=90)
cm.set_yticklabels(labels=['low', 'medium', 'high'])
cm.set_ylabel("Predicted",nfontsize=60)
cm.tick_params(labelsize=50)
plt.show()

sns.choose_colorbrewer_palette('sequential')

###make theoretical perfect heatmap
perfect = [[10, 0, 0], [0, 10, 0], [0, 0, 10]]
plt.figure()
sns.heatmap(perfect)
cm_perf = sns.heatmap(perfect,
                      square=True,
                      annot=False,
                      fmt='d',
                      cbar=True,
                      cmap='Blues')
cm_perf.set_xlabel("True", fontsize=50)
plt.xticks(rotation=0)
cm_perf.set_xticklabels(labels=['low', 'medium', 'high'])
plt.yticks(rotation=90)
Exemplo n.º 12
0
    'lapse': 1e-6,
    'N_values': (8, 12, 16),
    'g_values': np.linspace(1e-4, 1 - 1e-4, size),
    'subject_num': 1,
    'fine_sigma': fine_sigma,
    'punishment': 0,
    'fine_model': 'const',
    'reward_scheme': 'asym_reward',
    'num_samples': 50000,
    'opt_type': 'sig_reward'
}

prescolorvals = sns.color_palette('Blues_d', reward_vals.shape[0])
abscolorvals = sns.color_palette('Greens_d', reward_vals.shape[0])

pres_cmap = sns.choose_colorbrewer_palette('Blues_d', as_cmap=True)
abs_cmap = sns.choose_colorbrewer_palette('Greens_d', as_cmap=True)

maxlen = int(model_params['T'] / model_params['dt'])


def rewardeval(reward):
    curr_params = deepcopy(model_params)
    curr_params['reward'] = reward
    print(np.where(reward_vals == reward)[0][0])

    finegr = FineGrained(**curr_params)
    coarse_stats = finegr.coarse_stats

    N_blocked_model_params = []
    for j in range(len(model_params['N_values'])):
Exemplo n.º 13
0
sns.displot(hist_kws={'alpha':1}) # Make completely opaque




#--------- COLOR PALETTES --------#

#--------------------------------------------------
# http://matplotlib.org/examples/color/colormaps_reference.html
# http://chrisalbon.com/python/seaborn_color_palettes.html
# http://seaborn.pydata.org/tutorial/color_palettes.html
#--------------------------------------------------


# Color Brewer library has a great set of palettes
sns.choose_colorbrewer_palette() #
sns.choose_colorbrewer_palette(data_type=) #data_type = {'sequential', 'diverging', 'qualitative'}


#------ QUALITATIVE 

sns.color_palette(palette=) 
# for qualitative color palettes, involving 6 or fewer factors
palette = deep, muted, pastel, bright, dark, colorblind
# more than 6 factors
sns.palplot(sns.color_palette('hls', n_colors=)) # n_colors =  the number of colors
sns.palplot(sns.color_palette('huls', n_colors=)) # keeps brightness even


#------ SEQUENTIAL