如何在小提琴图中将多个熊猫数据框绘制为单独的类别?

时间:2015-10-14 20:57:51

标签: python numpy pandas matplotlib seaborn

我正在阅读来自不同类别的四个单独文件的数据,并希望可视化使用小提琴情节的人的分布。在我的尝试中,似乎他们被覆盖了

import seaborn as sb

# category1, category2, category3, category4 are pandas dataFrame obj

sb.violinplot(category1['delay'])
sb.violinplot(category2['delay'])
sb.violinplot(category3['delay'])
sb.violinplot(category4['delay'])

1 个答案:

答案 0 :(得分:1)

以上@BernBarn建议的证据:

import seaborn as sns
df = pd.DataFrame({'col1': np.random.rand(100), 'col2': np.random.rand(100)})
sns.violinplot(df);

enter image description here

或者,如果你需要结合你的几个df:

df = pd.concat([category1['delay'],
                category2['delay'],
                category3['delay'],
                category4['delay']],
                axis=1)
sns.violinplot(df);