值在条形图上无法正确显示

时间:2019-08-25 17:36:50

标签: python matplotlib

我当前正在尝试在标签上正确显示标签。

[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]

当前显示为百分比(7559%),而不是(75.59%)

1 个答案:

答案 0 :(得分:1)

您可以尝试使用'{}%'.format(height)代替'{:.0%}.format(height)'

来自Standard Format Specifiers

  

'%'-百分比。将数字乘以100并显示         固定('f')格式,后跟一个百分号。

相关问题