小编cod*_*nny的帖子

matplotlib/Seaborn 中的条形标签

在版本 3.4 中,matplotlib 添加了自动 Bar 标签: https://matplotlib.org/stable/users/whats_new.html#new-automatic-labeling-for-bar-charts

我正在尝试在 Seaborn 生成的条形图上使用它。

fig, axs = plt.subplots(
        nrows=2,
    )        

for i, col in enumerate(['col_1', 'col_2']):
        ax = axs[i]
        sns.barplot(
            x="class",
            y=col,
            hue="hue_col",
            data=data_df,
            edgecolor=".3",
            linewidth=0.5,
            ax=ax
        )


        ax.bar_label(ax.containers[i]) # Doesn't work
Run Code Online (Sandbox Code Playgroud)

我需要做什么才能使这项工作成功?示例图

python matplotlib seaborn

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

matplotlib ×1

python ×1

seaborn ×1