gpt4 book ai didi

python - 条形图上的值无法正确显示

转载 作者:行者123 更新时间:2023-12-01 07:22:09 25 4
gpt4 key购买 nike

我目前正在尝试正确显示栏上的标签。

[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%)

最佳答案

您可以尝试'{}%'.format(height)而不是'{:.0%}.format(height)'

来自 Standard Format Specifiers :

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

关于python - 条形图上的值无法正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57648279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com