Boxenplot可以看做是加强版的Boxplot,适用于大数据,能更方便真实的反应数据情况。这种图原来叫做“letter value” plot,是用分位数来反应数据情况。
Seaborn中主要参数为:
seaborn.boxenplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, orient=None, color=None, palette=None, saturation=0.75, width=0.8, dodge=True, k_depth='proportion', linewidth=None, scale='exponential', outlier_prop=None, ax=None, **kwargs)
还是看几个例子:
基础作图:
import seaborn as sns
sns.set(style="whitegrid")
tips = sns.load_dataset("tips")
ax = sns.boxenplot(x=tips["total_bill"])
single
简单分组:
ax = sns.boxenplot(x="day", y="total_bill", data=tips)
group
分组并移动legend的位置:
import matplotlib.pyplot as plt
ax = sns.boxenplot(x="day", y="total_bill", hue="smoker",
data=tips, palette="Set3")
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
group and change legend
加点,与boxplot类似:
ax = sns.boxenplot(x="day", y="total_bill", data=tips)
ax = sns.stripplot(x="day", y="total_bill", data=tips,
size=4, color="gray")
stripplot
同样用catplot分面:
g = sns.catplot(x="sex", y="total_bill",
hue="smoker", col="time",
data=tips, kind="boxen",
height=4, aspect=.7)
catplot
diamonds = sns.load_dataset("diamonds")
ax = sns.catplot(x="color", y="price", kind="boxen",
data=diamonds.sort_values("color"))
plt.savefig('fig.png', dpi=500) #指定分辨率
catplot2
网友评论