Home > front end >  Seaborn barplot display numeric values from groupby
Seaborn barplot display numeric values from groupby

Time:04-22

Data from: enter image description here

The issue is that it is only displaying the values for the 'Lower Middle Income' bars.

I assume that this is somehow a function of the groupby used to create the df, but I have never had this happen before.

The values are all present:

                   country iso3c          incomeLevel  Intentional homicides (per 100,000 people)
68             El Salvador   SLV  Lower middle income                                      74.178
47                Colombia   COL  Upper middle income                                      50.996
102               Honduras   HND  Lower middle income                                      47.886
218           South Africa   ZAF  Upper middle income                                      42.121
119                Jamaica   JAM  Upper middle income                                      40.821
137                Lesotho   LSO  Lower middle income                                      36.921
256          Venezuela, RB   VEN       Not classified                                      36.432
258  Virgin Islands (U.S.)   VIR          High income                                      35.765
177                Nigeria   NGA  Lower middle income                                      34.524
95               Guatemala   GTM  Upper middle income                                      33.251 

I want the values displayed on all of the bars, not just the 'Lower Middle Income' bars.

CodePudding user response:

Each hue value leads to one entry in ax.containers. You can loop through them to add the labels.

Some additional remarks:

  • Matplotlib has both an "old" pyplot interface and a "new" calling bar_label for sns.barplot with hue

  • Related