首页 > 解决方案 > 如何将文本放在中心以便您可以清楚地看到它?以及如何去掉每个数字末尾的零?

问题描述

当我对数字进行四舍五入时,我遇到了难以看到文本和最后为零的问题。我该如何解决?

这是我的代码:

x = avgs['Category']  
y = round(avgs['avg_goal'])
fig, ax = plt.subplots()    
width = 0.65 
ind = np.arange(len(y))  
ax.barh(ind, y, width, color="blue")
ax.set_yticks(ind+width/2)
ax.set_yticklabels(x, minor=False)
plt.title('Average Goal of Each Kickstarter Category')
plt.xlabel('Average Goal')
plt.ylabel('y')
for i, v in enumerate(y):
    ax.text(v + 3, i + .25, str(v), color='blue')
plt.show()

结果如下:

结果

将不胜感激一些帮助,谢谢!

标签: pythonmatplotlibplotbar-chart

解决方案


推荐阅读