Seaborn Barplot - Displaying Values

后端 未结 6 779
不知归路
不知归路 2020-11-27 14:39

I\'m looking to see how to do two things in Seaborn with using a bar chart to display values that are in the dataframe, but not in the graph

1) I\'m looking to displ

6条回答
  •  Happy的楠姐
    2020-11-27 14:55

    A simple way to do so is to add the below code (for Seaborn):

    for p in splot.patches:
        splot.annotate(format(p.get_height(), '.1f'), 
                       (p.get_x() + p.get_width() / 2., p.get_height()), 
                       ha = 'center', va = 'center', 
                       xytext = (0, 9), 
                       textcoords = 'offset points') 
    

    Example :

    splot = sns.barplot(df['X'], df['Y'])
    # Annotate the bars in plot
    for p in splot.patches:
        splot.annotate(format(p.get_height(), '.1f'), 
                       (p.get_x() + p.get_width() / 2., p.get_height()), 
                       ha = 'center', va = 'center', 
                       xytext = (0, 9), 
                       textcoords = 'offset points')    
    plt.show()
    

提交回复
热议问题