我想为我的
sns
直方图添加标签。我用过 plt.text
但它与框架的边缘发生碰撞。
我怎样才能阻止它这样做?或者 - 有没有更好的方法来添加标签?
谢谢。
plt.figure(figsize=(7, 4))
hist = sns.histplot(x='y', data=data, hue='y', palette=palette, legend=False)
for p in hist.patches:
x = p.get_x() + p.get_width() / 2
if p.get_height() != 0:
txt = plt.text(x=x, y=p.get_height() + 1000, s=p.get_height(), ha='center')