我正在尝试生成不同的箱线图来描述某些产品系列和行业组(“生产”、“贸易”、“商业”、“休闲与福利”)的变量分布。
我想知道:
- 如果有办法在子图标题中只显示“生产”、“贸易”、“商业”和“休闲与福利”,而不是每次都显示“industry_group = Production”等等
- 如果有办法从每个子图的上边界稍微提高这些子图标题(在我发布的图像中,您可以清楚地看到它们没有空间)
在我正在使用的代码下方,这里有一张图片向您展示我得到的内容 --> Catplot Image。
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_context("talk")
boxplot = sns.catplot(
x='family',
y='lag',
hue="SF_type",
col="industry_group",
data=df1,
kind="box",
orient="v",
height=8,
aspect=2,
col_wrap=1,
order=fam_sort,
palette='Set3',
notch=True,
legend=True,
legend_out=True,
showfliers=False,
showmeans=True,
meanprops={
"marker":"o",
"markerfacecolor":"white",
"markeredgecolor":"black",
"markersize":"10"
}
)
boxplot.fig.suptitle("Boxplots by Product Basket, Industry Group & SF Type", y=1.14)
#repeat xticks for each plot
for ax in boxplot.axes:
plt.setp(ax.get_xticklabels(), visible=True, rotation=75)
plt.subplots_adjust(hspace=1.2, top = 1.1)
#remove axis titles
for ax in boxplot.axes.flatten():
ax.set_ylabel('')
ax.set_xlabel('')
limit_upper = max(df1.groupby(['family','SF_type','industry_group'])['lag'].quantile(0.75))
plt.setp(ax.texts, text="")
ax.set(ylim=(-10, limit_upper ))
猫图图像