【问题标题】:Matplotlib - Adding value labels to bar graph [duplicate]Matplotlib - 向条形图添加值标签[重复]
【发布时间】:2022-01-11 01:43:12
【问题描述】:

我一直在尝试在每个条形图上绘制带有值标签的条形图。我已经搜索了所有内容,但无法完成。我的df是下面那个。

Pillar                       % 
Exercise                    19.4
Meaningful Activity         19.4
Sleep                        7.7
Nutrition                   22.9
Community                   16.2
Stress Management           23.9

到目前为止我的代码是

df_plot.plot(x ='Pillar', y='%', kind = 'bar')
plt.show()

【问题讨论】:

    标签: pandas matplotlib


    【解决方案1】:

    使用ax.bar_label:

    ax = df.plot(x='Pillar', y='%', kind='bar', legend=False, rot=0)
    ax.bar_label(ax.containers[0], label_type='edge')
    plt.tight_layout()
    

    【讨论】:

      猜你喜欢
      • 2019-01-01
      • 2022-01-16
      • 2015-05-09
      • 1970-01-01
      • 1970-01-01
      • 2016-07-06
      相关资源
      最近更新 更多