python - 如何将文本放在中心以便您可以清楚地看到它?以及如何去掉每个数字末尾的零?
问题描述
当我对数字进行四舍五入时,我遇到了难以看到文本和最后为零的问题。我该如何解决?
这是我的代码:
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()
结果如下:
将不胜感激一些帮助,谢谢!
解决方案
推荐阅读
- rust - 如何在 rust 中使用全局变量?
- c++ - 如何用一个 if 语句替换此代码?
- postgresql - Postgresql 相当于 mysql ON DUPLICATE KEY UPDATE
- uri - 我无法在 eXist-db 中使用一个 html 文件呈现不同的数据文件
- docker - 以编程方式创建气流池
- amazon-web-services - 如何在 redash 服务器后面设置代理
- kotlin - Kotlin/Native 与 Swift 的互操作性:使用具有相同签名的两个方法生成的接口
- laravel - 使用 paratest 运行代码覆盖时未创建数据库
- python - 如何在 python tkinter 中舍入到 2 位小数
- python - 获取特定属性实例的 slug 列表