How to use the seaborn.factorplot function in seaborn

To help you get started, we’ve selected a few seaborn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ComparativeGenomicsToolkit / Comparative-Annotation-Toolkit / cat / plots.py View on Github external
def denovo_plot(consensus_data, ordered_genomes, denovo_tgt):
    with denovo_tgt.open('w') as outf, PdfPages(outf) as pdf:
        try:
            df = json_biotype_nested_counter_to_df(consensus_data, 'denovo')
        except ValueError:
            # No de novo results. Probably the test set.
            return
        # fix column names because json_biotype_nested_counter_to_df makes assumptions
        df.columns = ['Result', 'Number of transcripts', 'Augustus mode', 'genome']
        has_pb = len(set(df['Augustus mode'])) == 2
        if len(set(df.genome)) > 1:  # if we ran in PB only, we may not have multiple genomes
            if has_pb is True:
                ax = sns.factorplot(data=df, x='genome', y='Number of transcripts', kind='bar', col='Result',
                                    hue='Augustus mode', col_wrap=2, row_order=ordered_genomes, sharex=True,
                                    sharey=False)
            else:
                ax = sns.factorplot(data=df, x='genome', y='Number of transcripts', kind='bar', col='Result',
                                    col_wrap=2, row_order=ordered_genomes, sharex=True, sharey=False)
        else:
            if has_pb is True:
                ax = sns.factorplot(data=df, x='Result', y='Number of transcripts', kind='bar', hue='Augustus mode')
            else:
                ax = sns.factorplot(data=df, x='Result', y='Number of transcripts', kind='bar')
        ax.set_xticklabels(rotation=90)
        ax.fig.suptitle('Incorporation of de-novo predictions')
        ax.fig.subplots_adjust(top=0.9)
        multipage_close(pdf, tight_layout=False)
github danleh / wasabi / eval / results / runtime-analysis.py View on Github external
])

# print df
# print df.dtypes

sns.set_style("ticks")
sns.set_palette(
	sns.xkcd_palette(["pale red", "medium green", "denim blue"])
	# sns.color_palette("Set1", n_colors=3)
)

fp = mpl.font_manager.FontProperties(fname="/usr/share/fonts/truetype/fira/FiraSans-Regular.ttf")
# print fp
print mpl.font_manager.findfont("Fira Sans")

g = sns.factorplot(x="hooks", y="overhead", hue="program_group", kind="bar", aspect=5, size=2.2, data=df, legend=False,
	estimator=sp.stats.gmean,	
	errwidth=0,
	# errwidth=1,
	# capsize=.1
)
g.ax.yaxis.set_minor_locator(mpl.ticker.AutoMinorLocator())
g.despine(offset=4,bottom=True)
plt.xlabel("Instrumented Hooks", fontproperties=fp, fontsize=11,
	labelpad=-8
)
plt.ylabel("Relative Runtime", fontproperties=fp, fontsize=11,
#	position=(0,.3)
)

plt.legend()
handles, labels = g.ax.get_legend_handles_labels()
github DUanalytics / pyAnalytics / 71-plotGen / plot_legend.py View on Github external
#Plot - Legend
#-----------------------------
#%

#
#plt acts on the current axes. To get axes from a FacetGrid use fig. For example: 
g.fig.get_axes()[0].legend(loc='lower left')


#
import seaborn as sns
sns.set(style="whitegrid")

titanic = sns.load_dataset("titanic")

g = sns.factorplot("class", "survived", "sex",
                    data=titanic, kind="bar",
                    size=6, palette="muted",
                   legend_out=False)
g.despine(left=True)
g.set_ylabels("survival probability")

#
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)



#https://stackoverflow.com/questions/27019079/move-seaborn-plot-legend-to-a-different-position
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
matplotlib.style.use('ggplot')
github RuleWorld / bionetgen / moleculeTypeClustering.py View on Github external
for element in pandasc:
            pandasDistro[element].extend(pandasc[element])
    
    pandasDistro = pandas.DataFrame(data=pandasDistro)
    print pandasDistro
    with open('processDistro.dump','wb') as f:
        pickle.dump(processDistro,f)
        pickle.dump(pandasDistro,f)
    '''

    with open('processDistro.dump','rb') as f:
        processDistro = pickle.load(f)
        pandasDistro = pickle.load(f)

    
    sns.factorplot("process", "percentage", "database", pandasDistro,kind='bar',x_order=processOrder)
    plt.savefig('processBarChar2.png')
    print processDistro[0]

    f, axs = plt.subplots(3, 2, sharex=True, figsize=(8, 8))

    colors= sns.color_palette("Set1", 3)
    for color,direct in zip(colors,directory):
        for index,process in enumerate(processOrder):
            actions = np.array(pandasDistro[pandasDistro.process==process][pandasDistro.database == direct[1]]['percentage'].values)
            sns.kdeplot(actions, shade=True,color=color,label=direct[1],ax=axs[index/2][index%2],clip=(0,1))
            ax=axs[index/2][index%2].set_title(process)
            axs[index/2][index%2].set_xlim([0,1])
    plt.savefig('processDensity.png')

    g = sns.FacetGrid(pandasDistro, row="process", col="database", hue="database",
        margin_titles=True,row_order=processOrder,xlim=(0,1))
github czhuang / ChordRipple / app / Database.py View on Github external
def plot_stats_by_step_single(self, num_changes, plot_id):
        num_changes = self.collapse_users(num_changes)
        flattened = []
        for step_idx, counts in num_changes.iteritems():
            for j, count in enumerate(counts):
                flattened.append([step_idx+1, count, 0])

        df = pd.DataFrame(data=np.array(flattened),
                          columns=['chord_position', 'num_chord_changes', 'unique'])

        sns.plt.clf()

        sns.set(style="whitegrid")
        g = sns.factorplot(x='chord_position', y='num_chord_changes', hue='unique', data=df,
                           size=6, kind="bar", palette="muted")
        g.despine(left=True)
        plt.legend(loc='upper right')
        plt.savefig(os.path.join(PLOT_DIR, '%s.pdf' % plot_id))
github DUanalytics / pyAnalytics / 74-sns / sns_factorplot.py View on Github external
mtcars = data('mtcars')
mtcars.head()

import seaborn as sns
sns.set(rc={'figure.figsize':(3,2)})
# Factor Plot -separate plots by categorical classes
g=sns.factorplot(x='gear',  y='carb',  data=mtcars, hue='cyl', col='am',  kind ='swarm') 
# Color by am, # Separate by cyl # Swarmplot
# Rotate x-axis labels
g.set_xticklabels(rotation=-45)
 
# Doesn't work because only rotates last plot
# plt.xticks(rotation=-45)


g=sns.factorplot(x='gear',  y='carb',  data=mtcars, hue='cyl', col='am',  kind ='swarm', aspect=1/1, legend=True)
github Seanny123 / DeepSLAM / panda_plots.py View on Github external
avg_results = pd.concat([max_add, avg_results])

      bar = sns.factorplot('Network', metric, 'AVG', data=avg_results, kind=kind, size=6,
                           legend=False, order=order)

      bar.axes[0,0].set_title(title)
      handles, labels = bar.axes[0,0].get_legend_handles_labels()
      bar.axes[0,0].legend(handles, ['Max', 'Average'], loc='center left', bbox_to_anchor=(1, 0.5))

  else: # show boosted and non-boosted and not max
    results = results[(results['AVG'] == True)]
    bar = sns.factorplot('Network', 'F1 Score', 'Boosted', data=results, kind=kind, size=6,
                         legend=True, order=order)
    bar.axes[0,0].set_title(title)

    bar = sns.factorplot('Network', 'Precision', 'Boosted', data=results,
                         kind=kind, size=6, legend=True, order=order)
    bar.axes[0,0].set_title(title)

    bar = sns.factorplot('Network', 'Recall', 'Boosted', data=results, kind=kind, size=6,
                         legend=True, order=order)
    bar.axes[0,0].set_title(title)

else:
  results = results[(results['AVG'] == False)]
  kind = 'point'
  network_names = ['GoogLeNet', 'OverFeat', 'Cifar10', 'AlexNet', 'VGG19']
  # Silly things because Python is weird
  tmp = range(22)
  tmp.remove(1)
  order = {'GoogLeNet':['1', '2', '3a','3b','4a','4b','4c','4d','4e','5a','5b'],
           'OverFeat':tmp,
github cosanlab / nltools / examples / 02_Analysis / plot_decomposition.py View on Github external
import pandas as pd

wt =  pd.DataFrame(output['weights'])
wt['PainIntensity'] = data_center.X['PainLevel'].replace({1:'Low',
														  2:'Medium',
														  3:'High'}
														 ).reset_index(drop=True)

wt_long = pd.melt(wt,
				  value_vars=range(n_components),
				  value_name='Weight',
				  var_name='Component',
				  id_vars='PainIntensity')

with sns.plotting_context(context='paper', font_scale=2):
    sns.factorplot(data=wt_long,
                    y='Weight',
                    x='PainIntensity',
                    hue='Component',
                    order=['Low','Medium','High'],
                    aspect=1.5)
github jianhaod / Kaggle / 1.1_Titanic / src / Titanic.py View on Github external
# Cabin/Survived
    DataSet.loc[DataSet.Cabin.isnull(), 'Cabin'] = 'U0'
    DataSet['Has_Cabin'] = DataSet['Cabin'].apply(lambda x: 0 if x == 'U0' else 1)
    DataSet[['Has_Cabin','Survived']].groupby(['Has_Cabin']).mean().plot.bar()
    # create feature for the alphabetical part of the cabin number
    DataSet['CabinLetter'] = DataSet['Cabin'].map(lambda x: re.compile("([a-zA-Z]+)").search(x).group())
    # convert the distinct cabin letters with incremental integer values
    DataSet['CabinLetter'] = pd.factorize(train_data['CabinLetter'])[0]
    DataSet[['CabinLetter','Survived']].groupby(['CabinLetter']).mean().plot.bar()
    
    # Embarked/Survived
    sns.countplot('Embarked', hue='Survived', data = DataSet)
    plt.title('Embarked and Survived')
    
    sns.factorplot('Embarked', 'Survived', data=train_data, size=3, aspect=2)
    plt.title('Embarked and Survived rate')
    plt.show()
github APPIAN-PET / APPIAN / src / qc.py View on Github external
if plot_type == "measure" : 
            unique_measure =np.unique(df.measure)
            nMeasure = np.unique(unique_measure)

        unique_metric = np.unique(df.metric)
        nMetric = len(unique_metric)
        #fig, axes = plt.subplots(nrows=nROI, ncols=nMetric)
        for roi, i in zip(np.unique(df.roi), range(nROI)):
            df0=df[ (df.roi==roi)  ]
            for metric in unique_metric :
                x=df0.value[df.metric == metric]
                #df0.value.loc[df.metric == metric]= (x-np.min(x))/(np.max(x)-np.min(x))

            if plot_type == "measure" : 
                sns.factorplot(x="metric", col="measure", y="value", kind="swarm",  data=df0, legend=False, hue="sub")
                #plt.title("Outlier Measure: "+df0.analysis.iloc[0] )
            else : 
                sns.factorplot(x="metric", y="value",   data=df0,  kind="swarm",  hue="sub")
                #plt.title("QC Metric: " + df0.analysis.iloc[0] )
            plt.ylabel('')
            plt.xlabel('')
            #if nROI > 1 : plt.title("ROI Label: "+str(roi))

            ax.spines['top'].set_visible(False)
            ax.spines['right'].set_visible(False)
            plt.ylim([-0.05,1.05])
            plt.legend(bbox_to_anchor=(1.05, 1), loc="upper right", ncol=1, prop={'size': 6})
        if not isdefined( self.inputs.out_file) :
            self.inputs.out_file = self._gen_output()
        print('Out file:', self.inputs.out_file)
        #plt.tight_layout()