-1
ax0 = sns.barplot(x='techies', y=df.index, data=df, color = "b", label="techies")

Produces this:

enter image description here

I want now to place an annotation just to the inside of the end of each bar with a number corresponding to its value. I need therefore (I think) to iterate through each bar, and place an annotation with the correct coordinate offset to get it there. But I cannot figure out how to get there.

Update

Notice that I am asking about doing this with Seaborn. The linked possible duplicate is with matplotlib which is different. (Thanks @dux and @xg.plt.py)

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
pitosalas
  • 10,286
  • 12
  • 72
  • 120
  • @xg.plt.py Why this question might be answered in your suggested duplicate, I feel most users would like to see the answer in an individual question – Dux Jun 07 '18 at 01:21
  • Actually, the solution in the linked answer doesn't work here, since, here, `seaborn` is used, and `barplot` has a different signature than `pyplot.barh` – Dux Jun 07 '18 at 01:41
  • 1
    Possible duplicate of [Seaborn Barplot - Displaying Values](https://stackoverflow.com/questions/43214978/seaborn-barplot-displaying-values) – ImportanceOfBeingErnest Jun 07 '18 at 10:05

1 Answers1

-1

This should work

values = df.techies.groupby(df.index).mean()
for i, v in enumerate(values):
    ax.text(v,  i-0.1, '%.2f' % v, fontsize=10)

Example with a sample dataset

import seaborn as sns
tips = sns.load_dataset("tips")
ax = sns.barplot(y="day", x="total_bill", data=tips)
for i, v in enumerate(tips.groupby('day').total_bill.mean()):
    ax.text(v,  i-0.1, '%.2f' % v, fontsize=10)

enter image description here

phi
  • 10,572
  • 3
  • 21
  • 30