【发布时间】:2021-05-09 20:59:25
【问题描述】:
我想用从最小到最大的盒子绘制 seaborn boxplot,而不是从第 2 到第 3 个四分位数,我可以在 matplotlib 或 seaborn 中控制它吗?我知道我可以控制胡须 - 盒子怎么样?
【问题讨论】:
标签: matplotlib seaborn boxplot
我想用从最小到最大的盒子绘制 seaborn boxplot,而不是从第 2 到第 3 个四分位数,我可以在 matplotlib 或 seaborn 中控制它吗?我知道我可以控制胡须 - 盒子怎么样?
【问题讨论】:
标签: matplotlib seaborn boxplot
这是一种使用聚合数据框通过水平图模拟 seaborn 箱线图的方法。
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# set sns plot style
sns.set()
tips = sns.load_dataset('tips')
fig, (ax1, ax2) = plt.subplots(nrows=2)
sns.boxplot(x='total_bill', y='day', data=tips, ax=ax1)
day_min_max = tips[['day', 'total_bill']].groupby('day').agg(['min', 'max', 'median'])
day_min_max.columns = day_min_max.columns.droplevel(0) # remove the old column name, only leaving 'min' and 'max'
ax2.use_sticky_edges = False
sns.barplot(y=day_min_max.index, x=day_min_max['median'] - day_min_max['min'], left=day_min_max['min'], ec='k', ax=ax2)
sns.barplot(y=day_min_max.index, x=day_min_max['max'] - day_min_max['median'], left=day_min_max['median'], ec='k', ax=ax2)
plt.tight_layout()
plt.show()
【讨论】:
【讨论】:
sns.barplot(x=..., y=data.ptp(axis=1), bottom=data.min(axis=1)),因为y 是从bottom 开始的条形高度。使用y=data.max(axis=1),条形从min 变为min+max。
height 是一个亲戚height 不想进入我的大脑。现已编辑。