I'm trying to generate different boxplots that are describing the distribution of a variable for some product families and industry groups ("Production", "Trade", "Business", "Leisure & Wellbeing").
I'd like to know:
- if there is a way to show only "Production", "Trade", "Business" and "Leisure & Wellbeing" in the subplots titles instead of having each time "industry_group = Production" and so on
- if there is a way to raise those subplot titles a little bit from the upper border of each subplot (in the image I'm posting you can clearly see that they have no space)
Below the code I'm using and here an image to show you what I get --> 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 ))
Catplot Image
It can be changed with set_titles(). {} to specify the column or row that is being subplotted. See docstring for more details, and the example in the official seaborn reference to modify the subtitles.
default: