在版本 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)
我需要做什么才能使这项工作成功?示例图