How to display the value of the bar on each bar with pyplot.barh()?

后端 未结 9 647
不知归路
不知归路 2020-11-22 08:10

I generated a bar plot, how can I display the value of the bar on each bar?

Current plot:

\"enter

9条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 08:41

    For anyone wanting to have their label at the base of their bars just divide v by the value of the label like this:

    for i, v in enumerate(labels):
        axes.text(i-.25, 
                  v/labels[i]+100, 
                  labels[i], 
                  fontsize=18, 
                  color=label_color_list[i])
    

    (note: I added 100 so it wasn't absolutely at the bottom)

    To get a result like this:

提交回复
热议问题