admin管理员组文章数量:1315999
I have a dataframe for which I am plotting violin plot. The dataframe has two categories A and B and highly imbalance data (one df has 1000 samples/rows and other has 200). I want to compare both categories and I believe looking at violin plot will give more information about distribution. While plotting it, I can plot two violins for separate groups. However, I want left side to represent category A while right side represent category B. I am able to plot it but what I also want is to keep the boxes, whiskers interquartile ranges etc. to be separate for each group. My plot has just one box in center (image 1). I want something like as is in image 2 (ref: /).
Setting split=False is creating two separately voilins.
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# Sample data for df1 and df2
df1 = pd.DataFrame({
'category': ['A', 'A', 'B', 'B', 'B'],
'Value': [10, 200, 300, 40, 50]
})
df2 = pd.DataFrame({
'category': ['A', 'A', 'B', 'B', 'B'],
'Value': [3, 4, 5, 4, 1]
})
# Add group labels to each dataframe
df1['day'] = 'thurs'
df2['day'] = 'thurs'
# Combine the dataframes
combined_df = pd.concat([df1, df2])
# Plot violin chart
plt.figure(figsize=(10, 6))
sns.violinplot(x='day', y='Value', hue = 'category', data=combined_df, split=True)
plt.title('Violin Plot of df1 and df2')
plt.show()
本文标签: pythonViolin plotConcatenating two violins in oneStack Overflow
版权声明:本文标题:python - Violin plot - Concatenating two violins in one - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741994948a2409855.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论