Adding value labels on a matplotlib bar chart

后端 未结 5 2153
广开言路
广开言路 2020-11-22 08:24

I got stuck on something that feels like should be relatively easy. The code I bring below is a sample based on a larger project I\'m working on. I saw no reason to post all

5条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 08:30

    If you only want to add Datapoints above the bars, you could easily do it with:

     for i in range(len(frequencies)): # your number of bars
        plt.text(x = x_values[i]-0.25, #takes your x values as horizontal positioning argument 
        y = y_values[i]+1, #takes your y values as vertical positioning argument 
        s = data_labels[i], # the labels you want to add to the data
        size = 9) # font size of datalabels
    

提交回复
热议问题