如何更改我的 seaborn catplot 中的数字或行和列

tsh*_*izz 5 python data-visualization seaborn facet-grid catplot

我有一个看起来像这样的数据框: 数据框:

有几个不同的model_names。我正在尝试使用以下代码在 seaborn catplot 中绘制数据:

sns.set(style="whitegrid")
sns.catplot(x='model_name', y='score', hue='train_val_test', col='score_name',
            data=classification_scores, kind='bar', height=4, aspect=.8)
Run Code Online (Sandbox Code Playgroud)

以下是我得到的图表:图形

如何更改格式以使图形显示在 2x2 网格上?将它们全部放在一条线上太局促了。

Đor*_*lić 7

使用参数col_wraprow_wrap设置所需的列/行数。IE

sns.catplot(
    x='model_name',
    y='score',
    hue='train_val_test',
    col='score_name',
    col_wrap=3, #Set the number of columns you want.
    data=classification_scores,
    kind='bar',
    height=4,
    aspect=.8
)
Run Code Online (Sandbox Code Playgroud)

对于 3 列。类似地,如果row用于分类,则相应的变量称为row_wrap


tsh*_*izz 1

import seaborn as sns
import matplotlib.pyplot as plt
plt.figure(figsize=(16,10))
sns.set(style="whitegrid")

for ax_num, score in zip(range(1,5), ['f1', 'recall', 'accuracy', 'precision']):
    plt.subplot(2,2,ax_num)
    sns.barplot(x='model_name', y='score', hue='train_val_test',
                data=classification_scores[classification_scores['score_name'] == score])
    plt.xticks(rotation=15, fontsize=14)
    
plt.tight_layout()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述