0

I would like to create a barplot like following. I need to show values as percentage on each bar like following. I it to do using seabron barplot.

I searched over the stack overflow but could not use them. My code looks something like following:

plt.figure(figsize=(10,6))
clrs = ['grey' if (x < max(df1['Score'])) else 'red' for x in df1['Score'] ]
sns.barplot(x='Languages',y='Score',data=df1,palette=clrs)

for spine in plt.gca().spines.values():
    spine.set_visible(False)


  plt.xlabel("")
  plt.ylabel("")
  frame1=plt.gca()

  frame1.axes.get_yaxis().set_ticks([])

for bar in bars:
    height = bar.get_height()
    plt.gca().text(bar.get_x() + bar.get_width()/2, bar.get_height() - 5, str(int(height)) + '%', 
             ha='center', color='w', fontsize=11)
  plt.show()

but it gives the following error: enter image description here

enter image description here

1 Answers1

0

The error tells you that the iterator bar is being interpreted as a module object.

Try to simply modify your loop as follows:

for b in bars:
    height = b.get_height()
    plt.gca().text(b.get_x() + b.get_width()/2, b.get_height() - 5, str(int(height)) + '%', 
             ha='center', color='w', fontsize=11)
CAPSLOCK
  • 6,243
  • 3
  • 33
  • 56