Ste*_*ini 2 python seaborn catplot
我正在尝试生成不同的箱线图,描述某些产品系列和行业组(“生产”、“贸易”、“商业”、“休闲与福祉”)的变量分布。
我想知道:
在我正在使用的代码下方,这里有一张图像向您展示我得到的内容 --> 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 ))
Run Code Online (Sandbox Code Playgroud)
Catplot 图像

可以使用 set_titles() 更改它。{} 指定要绘制子图的列或行。有关更多详细信息,请参阅文档字符串,以及官方seaborn参考中的示例来修改字幕。
签名: g.set_titles(template=None, row_template=None, col_template=None, **kwargs) 文档字符串:在每个面上方或网格边缘上绘制标题。
参数 template :带有格式化键 {col_var} 和 {col_name} (如果使用
col分面变量)和/或 {row_var} 和 {row_name} (如果使用row分面变量)的所有标题的字符串模板。row_template:在网格边距上绘制标题时行变量的模板。必须具有 {row_var} 和 {row_name} 格式键。col_template:在网格边距上绘制标题时行变量的模板。必须具有 {col_var} 和 {col_name} 格式化键。
import seaborn as sns
sns.set_theme(style="ticks")
titanic = sns.load_dataset("titanic")
g = sns.catplot(x="embark_town", y="age",
hue="sex", row="class",
data=titanic[titanic.embark_town.notnull()],
height=2, aspect=3, palette="Set3",
kind="violin", dodge=True, cut=0, bw=.2)
g.set_titles(template='{row_name}')
Run Code Online (Sandbox Code Playgroud)
默认:
| 归档时间: |
|
| 查看次数: |
1550 次 |
| 最近记录: |