Seaborn小提琴图分割要求任意的“ y”值

时间:2018-10-14 02:58:02

标签: python-3.x matplotlib seaborn

在seaborn中,我想绘制一个水平小提琴图。到目前为止,在我的测试中,我必须指定一个虚拟值作为常数列以用作y值。有没有更简单的方法?这似乎是一种hack,但如果不包含y参数,我似乎无法获得所需的行为。

谢谢!

import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np


def generate_dataframe() -> pd.DataFrame:

    df = pd.DataFrame(columns=['rand'])

    # normal variable
    df['rand'] = np.random.normal(size=(100,))

    # split by dummy
    df['ind'] = 'a'
    df['ind'].iloc[50:] = 'b'

    # I wouldn't think this would be needed
    df['y'] = "uhh"

    print(df)

    return df


def standard_violin_doesnt_work():

    plt.figure()

    # define dataframe
    df = generate_dataframe()
    sns.violinplot(x='rand', split=True, hue='ind', data=df)

    plt.show()

enter image description here

def standard_violin_does_work():

    plt.figure()

    # define dataframe
    df = generate_dataframe()
    sns.violinplot(x='rand', y='y', split=True, hue='ind', data=df)

    plt.show()

I guess this isnt bad?

0 个答案:

没有答案