向带注释的值添加数千个逗号分隔符

2024-06-16 11:00:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将数千个逗号分隔符添加到下图中每个条上方的显示值中(例如,(当前)13815(希望是)13815)。我可以这样做的y轴。请告知

我的代码如下所示:

a = df.opp.value_counts().plot(kind='bar')

#annotate bar plot with values
for p in a.patches:
    a.annotate(str(p.get_height()), (p.get_x() * 1.005, p.get_height() * 1.005))
    a.set_yticklabels(['{:,}'.format(int(x)) for x in bar_uk19_opptype.get_yticks().tolist()])

Plot


Tags: 代码indfforgetplotvaluebar
1条回答
网友
1楼 · 发布于 2024-06-16 11:00:48

使用:

a.annotate("{:,}".format(int(p.get_height())), (p.get_x() * 1.005, p.get_height() * 1.005))

编辑:刚刚意识到Aaron在评论alr中也有类似的ans

相关问题 更多 >