Skip to main content
 首页 » 编程设计

python之如何在 violinplot 中将多个 pandas 数据框绘制为单独的类别

2025年05月04日19yxwkf

我正在从四个不同类别的单独文件中读取数据,并且想为那些使用 fiddle 图的人可视化文件的分布。在我的尝试中,它们似乎被覆盖了

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']) 

请您参考如下方法:

你可以试试:

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

或者,如果您需要组合您的多个 df:

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