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

后端 未结 9 790
不知归路
不知归路 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:49

    Add:

    for i, v in enumerate(y):
        ax.text(v + 3, i + .25, str(v), color='blue', fontweight='bold')
    

    result:

    enter image description here

    The y-values v are both the x-location and the string values for ax.text, and conveniently the barplot has a metric of 1 for each bar, so the enumeration i is the y-location.

提交回复
热议问题