How to use the seaborn.barplot 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 algorithmica-repository / datascience / 2019-october / utils / common_utils.py View on Github external
def plot_feature_importances(estimator, X, cutoff=40):
    if isinstance(estimator, sklearn.linear_model.Lasso) :
        importances = estimator.coef_
    else:
        importances = estimator.feature_importances_
    indices = np.argsort(importances)[::-1][:cutoff]
    plt.figure()
    g = sns.barplot(y=X.columns[indices][:cutoff],x = importances[indices][:cutoff] , orient='h')
    g.set_xlabel("Relative importance",fontsize=12)
    g.set_ylabel("Features",fontsize=12)
    g.tick_params(labelsize=9)
    g.set_title("Feature importances based on: " + str(estimator).split('(')[0] + ' model' )
github LucaMarconato / weekly_diet / report.py View on Github external
def plot_into_axes(diet, ax0, ax1, legend_background_color=None):
    df = generate_daily_intake_information(diet)
    df['day'] = df.index
    sns.barplot(x='day', y='calories', data=df, color='red', ax=ax0)
    ax0.set_xlabel('')
    ax0.set_ylabel('kcal')
    ax0.axhline(3000, ls='--', color='red')

    df_melted = df.copy()
    df_melted.drop(['calories'], axis=1, inplace=True)
    df_melted = df_melted.melt(id_vars=['day'], value_vars=['carbohydrates', 'proteins', 'fats'])
    sns.barplot(x='day', y='value', hue='variable', data=df_melted, palette='deep', ax=ax1)
    ax1.set_xlabel('')
    legend = ax1.legend(ncol=3, bbox_to_anchor=(0.5, -0.3), loc='center')
    legend_colors = [x._facecolor for x in legend.legendHandles]
    if legend_background_color is not None:
        legend.get_frame().set_color(legend_background_color)
    ax1.axhline(400, ls='--', color=legend_colors[0])
    ax1.axhline(150, ls='--', color=legend_colors[1])
    ax1.axhline(80, ls='--', color=legend_colors[2])
github poldracklab / niworkflows / niworkflows / viz / plots.py View on Github external
if figure is None:
        plt.figure(figsize=(15, 5))
    gs = mgs.GridSpec(1, 21)
    ax0 = plt.subplot(gs[0, :10])
    ax1 = plt.subplot(gs[0, 11:])

    mask = np.zeros_like(corr, dtype=np.bool)
    mask[np.triu_indices_from(mask)] = True
    sns.heatmap(corr, linewidths=0.5, cmap="coolwarm", center=0, square=True, ax=ax0)
    ax0.tick_params(axis="both", which="both", width=0)

    for tick in ax0.xaxis.get_major_ticks():
        tick.label.set_fontsize("small")
    for tick in ax0.yaxis.get_major_ticks():
        tick.label.set_fontsize("small")
    sns.barplot(
        data=gscorr,
        x="index",
        y=reference,
        ax=ax1,
        order=gs_descending,
        palette="Reds_d",
        saturation=0.5,
    )

    ax1.set_xlabel("Confound time series")
    ax1.set_ylabel("Magnitude of correlation with {}".format(reference))
    ax1.tick_params(axis="x", which="both", width=0)
    ax1.tick_params(axis="y", which="both", width=5, length=5)

    for tick in ax1.xaxis.get_major_ticks():
        tick.label.set_fontsize("small")
github lukasturcani / stk / stk / ga / plotting.py View on Github external
for ind, selection_count in counter.items():
        label = f'{ind.name} - {ind.fitness}'
        data = {
            'Molecule: name - fitness value': label,
            'Number of times selected': selection_count,
            'Fitness': ind.fitness
        }
        df = df.append(data, ignore_index=True)

    df = df.sort_values(['Number of times selected', 'Fitness'],
                        ascending=[False, False])
    norm = plt.Normalize(df['Fitness'].min(), df['Fitness'].max())
    sm = plt.cm.ScalarMappable(cmap='magma_r', norm=norm)
    sm.set_array([])

    ax = sns.barplot(
                x='Molecule: name - fitness value',
                y='Number of times selected',
                hue='Fitness',
                palette='magma_r',
                dodge=False,
                data=df)
    ax.get_legend().remove()
    ax.figure.colorbar(sm).set_label('Fitness')
    plt.xticks(rotation=90)
    plt.tight_layout()
    fig.savefig(plot_name, dpi=fig.dpi)
    plt.close('all')
github chainer / chainer-chemistry / examples / qm9 / plot.py View on Github external
def save_evaluation_plot(x, y, metric, filename):
    plt.figure()

    sns.set()
    ax = sns.barplot(y=x, x=y)

    for n, (label, _y) in enumerate(zip(x, y)):
        ax.annotate(
            s='{:.3f}'.format(abs(_y)),
            xy=(_y, n),
            ha='right',
            va='center',
            xytext=(-5, 0),
            textcoords='offset points',
            color='white')

    plt.title('Performance on qm9')
    plt.xlabel(metric)
    plt.savefig(filename)
github jianhaod / Kaggle / 1.1_Titanic / src / Titanic.py View on Github external
DataSet['Age'].describe()
    bins = [0, 12, 18, 65, 100]
    DataSet['Age_group'] = pd.cut(DataSet['Age'], bins)
    by_age = DataSet.groupby('Age_group')['Survived'].mean()
    by_age.plot(kind = 'bar')
    
    # name/Survived
    DataSet['Title'] = DataSet['Name'].str.extract(' ([A-Za-z]+)\.', expand=False)
    pd.crosstab(DataSet['Title'], DataSet['Sex'])
    DataSet[['Title','Survived']].groupby(['Title']).mean().plot.bar()
    
    # namelength/Survived
    fig, axis1 = plt.subplots(1,1,figsize=(18,4))
    DataSet['Name_length'] = DataSet['Name'].apply(len)
    name_length = DataSet[['Name_length','Survived']].groupby(['Name_length'],as_index=False).mean()
    sns.barplot(x='Name_length', y='Survived', data=name_length)

    # SibSp/Survived
    sibsp_df = DataSet[DataSet['SibSp'] != 0]
    no_sibsp_df = DataSet[DataSet['SibSp'] == 0]
    sibsp_df['Survived'].value_counts().plot.pie(labels=['No Survived', 'Survived'], autopct = '%1.1f%%')
    plt.xlabel('sibsp')
    
    plt.subplot(122)
    no_sibsp_df['Survived'].value_counts().plot.pie(labels=['No Survived', 'Survived'], autopct = '%1.1f%%')
    plt.xlabel('no_sibsp')
    plt.show()
    
    # Parch/Survived
    parch_df = DataSet[DataSet['Parch'] != 0]
    no_parch_df = DataSet[DataSet['Parch'] == 0]
github chakki-works / arXivTimesIndicator / arxivtimes_indicator / visualization / visualize.py View on Github external
def save_bar_graph(x, y, file_name):
    plt.clf()
    sns.set_style("whitegrid")
    ax = sns.barplot(x=x, y=y)
    for item in ax.get_xticklabels():
        item.set_rotation(15)
    plt.savefig(file_name)
github BlueBrain / NeuroMorphoVis / scripts / plotting / plot.py View on Github external
plt.bar(X + 0.00, data[0], color = 'b', width = 0.25)
plt.bar(X + 0.25, data[1], color = 'g', width = 0.25)
plt.bar(X + 0.50, data[2], color = 'r', width = 0.25)

plt.savefig('%s/dist-1.pdf' % os.getcwd(), bbox_inches='tight')


df = pandas.DataFrame({
    'Factor': x,
    'Min': y,
    'Avg': z,
    'Max': k})

fig, ax1 = plt.subplots(figsize=(10, 10))
tidy = df.melt(id_vars='Factor').rename(columns=str.title)
sns.barplot(x='Factor', y='Value', hue='Variable', data=tidy, ax=ax1)
github PhantomInsights / mexican-government-report / scripts / step3.py View on Github external
df : pandas.DataFrame
        The DataFrame to be plotted.

    """

    # Small fix for programa and programar.
    df.loc[df["lemma_lower"] == "programa", "lemma_lower"] = "programar"

    # Only take into account alphabet tokens that are longer than 1 character and are not stop words.
    words = df[
        (df["is_alphabet"] == True) &
        (df["is_stopword"] == False) &
        (df["lemma_lower"].str.len() > 1)
    ]["lemma_lower"].value_counts()[:20]

    sns.barplot(x=words.values, y=words.index, palette="Blues_d", linewidth=0)
    plt.xlabel("Occurrences Count")
    plt.title("Most Frequent Words")
    plt.savefig("words_counts.png", facecolor="#5C0E10")
github pedro-abreu / deep-action-detection / code / code_AVA / rgb_balance_sampling.py View on Github external
class_weights = np.zeros(30)
    for i in y:
        class_weights[i] += 1

    for i in range(len(class_weights)):
        if class_weights[i] != 0.0:
            if penalizing_method == 'balanced':
                print(str(i) + " " + str(class_weights[i]) + " " + str(len(y) / (class_weights[i])))
                class_weights[i] = len(y) / (30 * class_weights[i])
            elif penalizing_method == 'weighted_log':
                print(str(i) + " " + str(class_weights[i]) + " " + str(math.log(mu * len(y) / (class_weights[i]))))
                class_weights[i] = math.log(mu * len(y) / (class_weights[i]))
        else:
            print(str(i) + " " + str(class_weights[i]) + " inf ")
            class_weights[i] = 0.0
    g = sns.barplot(x=[str(i) for i in range(len(class_weights))], y=class_weights)
    plt.xticks(rotation=-90)
    plt.title("Class weights " + penalizing_method)
    plt.grid(True)
    plt.show()

    class_dictionary = {}
    print(len(class_weights))
    for i in range(len(class_weights)):
        class_dictionary[i] = class_weights[i]
    print(class_dictionary)

    it = iter(class_weights)
    seclist = [utils.POSE_CLASSES, utils.OBJ_HUMAN_CLASSES, utils.HUMAN_HUMAN_CLASSES]
    class_lists = [list(islice(it, 0, i)) for i in seclist]
    print(class_lists)