Python seaborn 模块,violinplot() 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用seaborn.violinplot()

项目:tensorflow-deep-qa    作者:shuishen112    | 项目源码 | 文件源码
def overlap_visualize():
    train,test,dev = load("nlpcc",filter=True)
    test = test.reindex(np.random.permutation(test.index))
    df = test
    df['qlen'] = df['question'].str.len()
    df['alen'] = df['answer'].str.len()

    df['q_n_words'] = df['question'].apply(lambda row:len(row.split(' ')))
    df['a_n_words'] = df['answer'].apply(lambda row:len(row.split(' ')))

    def normalized_word_share(row):
        w1 = set(map(lambda word: word.lower().strip(), row['question'].split(" ")))
        w2 = set(map(lambda word: word.lower().strip(), row['answer'].split(" ")))    
        return 1.0 * len(w1 & w2)/(len(w1) + len(w2))
    df['word_share'] = df.apply(normalized_word_share, axis=1)

    plt.figure(figsize=(12, 8))
    plt.subplot(1,2,1)
    sns.violinplot(x = 'flag', y = 'word_share', data = df[0:50000])
    plt.subplot(1,2,2)
    sns.distplot(df[df['flag'] == 1.0]['word_share'][0:10000], color = 'green')
    sns.distplot(df[df['flag'] == 0.0]['word_share'][0:10000], color = 'red')

    print evaluation.evaluationBypandas(test,df['word_share'])
    plt.show('hold')
项目:DAB_analyzer    作者:meklon    | 项目源码 | 文件源码
def plot_group(data_frame, path_output):
    # optional import
    import seaborn as sns
    path_output_image = os.path.join(path_output, "summary_statistics.png")

    # # Plotting swarmplot
    # plt.figure(num=None, figsize=(15, 7), dpi=120)
    # sns.set_style("whitegrid")
    #
    # plt.title('Violin plot with single measurements')
    # sns.violinplot(x="Group", y="DAB+ area", data=data_frame, inner=None)
    # sns.swarmplot(x="Group", y="DAB+ area", data=data_frame, color="w", alpha=.5)
    # plt.savefig(path_output_image)
    #
    # plt.tight_layout()

    sns.set_style("whitegrid")
    sns.set_context("talk")
    plt.figure(num=None, figsize=(15, 7), dpi=120)
    plt.ylim(0, 100)
    plt.title('Box plot')
    sns.boxplot(x="Group", y="DAB+ area, %", data=data_frame)

    plt.tight_layout()
    plt.savefig(path_output_image, dpi=300)
项目:coquery    作者:gkunter    | 项目源码 | 文件源码
def plot_fnc(self, *args, **kwargs):
        sns.violinplot(*args, **kwargs)
项目:Comparative-Annotation-Toolkit    作者:ComparativeGenomicsToolkit    | 项目源码 | 文件源码
def horizontal_violin_plot(data, ordered_genomes, title, xlabel, pdf, hue=None, x=None, y=None, xlim=None):
    """not so generic function that specifically produces a paired boxplot/violinplot"""
    fig, ax = plt.subplots()
    sns.violinplot(data=data, x=x, y=y, hue=hue, order=ordered_genomes, palette=choose_palette(ordered_genomes),
                   saturation=boxplot_saturation, orient='h', cut=0, scale='count', ax=ax)
    fig.suptitle(title)
    ax.set_xlabel(xlabel)
    if xlim is not None:
        ax.set_xlim(xlim)
    multipage_close(pdf, tight_layout=False)
项目:act-rte-inference    作者:DeNeutoy    | 项目源码 | 文件源码
def sentence_length_vs_ponder_time(config,processed_data):

    plotting_data = []

    for  data in processed_data:

        steps = len(data["act_probs"])
        hyp_length = sum([1 for x in data["hypothesis"] if x!="PAD"])
        prem_length = sum([1 for x in data["premise"] if x!="PAD"])
        avg_length = (hyp_length + prem_length)/2
        correct = data["correct"]
        type_class = data["class"]
        plotting_data.append([steps, avg_length, correct, type_class])


    plotting_data = pd.DataFrame(np.vstack(plotting_data), columns=["steps", "avg_length", "correct", "class"])

    seaborn.violinplot(x="steps", y="avg_length",
                       hue="correct",split=True,
                       data=plotting_data, inner="quartile", scale="count")
    plt.show()
    # for class_type in [0.0,1.0,2.0]:
    #     fig = plt.figure()
    #     x_vals = [x[0] for x in plotting_data if (x[3]==class_type and x[2]==1.0)]
    #     y_vals = [x[1] for x in plotting_data if (x[3]==class_type and x[2]==1.0)]
    #     print("Class: ",class_type, "No. Correct: ", len(x_vals))
    #     plt.scatter(x_vals, y_vals,color="g")
    #
    #     x_vals = [x[0] for x in plotting_data if (x[3]==class_type and x[2]==0.0)]
    #     y_vals = [x[1] for x in plotting_data if (x[3]==class_type and x[2]==0.0)]
    #     print("Class: ",class_type, "No. Incorrect: ", len(x_vals))
    #
    #     plt.scatter(x_vals, y_vals,color="r")
    #
    #     ax = plt.gca()
    #     ax.set_xlabel("ACT Steps")
    #     ax.set_ylabel("avg hyp/premise length")
    #     ax.set_title("test_title")
    #     plt.show()
项目:real_estate    作者:cooperoelrichs    | 项目源码 | 文件源码
def violin_plot(filtered_data, output_file):
        plt.figure()
        plot = sns.violinplot(
            x="property_type", y="price_max",
            data=filtered_data,
            inner=None, figsize=(20, 20)
        )
        plot.get_figure().savefig(output_file)
项目:reinforcement-learning-an-introduction    作者:ShangtongZhang    | 项目源码 | 文件源码
def figure2_1():
    global figureIndex
    plt.figure(figureIndex)
    figureIndex += 1
    sns.violinplot(data=np.random.randn(200,10) + np.random.randn(10))
    plt.xlabel("Action")
    plt.ylabel("Reward distribution")
项目:crop-seq    作者:epigen    | 项目源码 | 文件源码
def gRNA_swarmplot(s1, s2, prefix=""):
    # Rank of gRNA change
    fig, axis = plt.subplots(3, 2, sharex=True, sharey=True, figsize=(8, 8))
    axis = axis.flatten()

    for i, screen in enumerate(s2.columns[::-1]):
        s = s1.join(s2)  # .fillna(0)
        s = s.iloc[np.random.permutation(len(s))]

        if ("TCR" in screen) or ("Jurkat" in screen) or ("stimulated" in screen) or ("unstimulated" in screen):
            s = s.ix[s.index[~s.index.str.contains("Wnt")]]
            if prefix.startswith("mid_screen-"):
                b = s["gDNA_Jurkat"]
            else:
                b = s["plasmid_pool_TCR"]
            x = s.ix[s.index[s.index.str.contains("Tcr")]]
            y = s.ix[s.index[s.index.str.contains("Essential")]]
            z = s.ix[s.index[s.index.str.contains("CTRL")]]
            b_x = b.ix[s.index[s.index.str.contains("Tcr")]]
            b_y = b.ix[s.index[s.index.str.contains("Essential")]]
            b_z = b.ix[s.index[s.index.str.contains("CTRL")]]
        elif ("WNT" in screen) or ("HEK" in screen):
            s = s.ix[s.index[~s.index.str.contains("Tcr")]]
            if prefix.startswith("mid_screen-"):
                if "_4_" in prefix:
                    b = s["gDNA_HEKclone4"]
                else:
                    b = s["gDNA_HEKclone6"]
            else:
                b = s["plasmid_pool_WNT"]
            x = s.ix[s.index[s.index.str.contains("Wnt")]]
            y = s.ix[s.index[s.index.str.contains("Essential")]]
            z = s.ix[s.index[s.index.str.contains("CTRL")]]
            b_x = b.ix[s.index[s.index.str.contains("Wnt")]]
            b_y = b.ix[s.index[s.index.str.contains("Essential")]]
            b_z = b.ix[s.index[s.index.str.contains("CTRL")]]

        fc_x = np.log2(1 + x[screen]) - np.log2(1 + b_x)
        fc_y = np.log2(1 + y[screen]) - np.log2(1 + b_y)
        fc_z = np.log2(1 + z[screen]) - np.log2(1 + b_z)

        fc_x.name = screen
        fc_y.name = "Essential"
        fc_z.name = "CTRL"

        sns.violinplot(x="variable", y="value", alpha=0.1, inner="box", data=pd.melt(pd.DataFrame([fc_x, fc_y, fc_z]).T), ax=axis[i])
        sns.swarmplot(x="variable", y="value", alpha=0.5, data=pd.melt(pd.DataFrame([fc_x, fc_y, fc_z]).T), ax=axis[i])
        axis[i].axhline(y=0, color='black', linestyle='--', lw=0.5)

        axis[i].set_title(screen)
    sns.despine(fig)
    fig.savefig(os.path.join(results_dir, "gRNA_counts.norm.{}.violin_swarmplot.svg".format(prefix)), bbox_inches="tight")