rahimijaffar
rahimijaffar

Reputation: 39

Values does not display correctly on bar chart

I am currently trying to display the label on the bar correctly.

[ax=dfp.plot(kind='bar', figsize= (20,8), width= (0.8), color=\['#5cb85c','#5bc0de','#d9534f'\])

plt.title("Percantage of Respondents' Interest in Data Science Areas", fontsize= 16)
plt.grid(False)
plt.xticks(fontsize=14)
plt.yticks()
plt.legend(fontsize=14)
ax.spines\['left'\].set_visible(True)
ax.spines\['right'\].set_visible(False)
ax.spines\['top'\].set_visible(False)

for i in ax.patches:
    width, height = i.get_width(), i.get_height()
    x, y = i.get_xy()`enter code here`
    ax.annotate('{:.0%}'.format(height), (x, y + height + 0.0))][1]

As it is currently display in the percentage (7559%) instead of (75.59%)

Upvotes: 1

Views: 64

Answers (1)

kederrac
kederrac

Reputation: 17322

you can try '{}%'.format(height) instead of '{:.0%}.format(height)'

from Standard Format Specifiers:

'%' - Percentage. Multiplies the number by 100 and displays in fixed ('f') format, followed by a percent sign.

Upvotes: 1

Related Questions