简体   繁体   English

值在条形图上显示不正确

[英]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%)因为它目前以百分比 (7559%) 而不是 (75.59%) 显示

you can try '{}%'.format(height) instead of '{:.0%}.format(height)'你可以试试'{}%'.format(height)而不是'{:.0%}.format(height)'

from Standard Format Specifiers :来自标准格式说明符

'%' - Percentage. '%' - 百分比。 Multiplies the number by 100 and displays in fixed ('f') format, followed by a percent sign.将数字乘以 100 并以固定 ('f') 格式显示,后跟一个百分号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM