我试图在Matplotlib中使用新的bar_标签选项,但找不到在标签值后附加文本的方法,例如“%”。以前,使用ax.text我可以使用f-strings,但我找不到将f-strings与条形标签方法结合使用的方法
fig, ax = plt.subplots(1, 1, figsize=(12,8))
hbars = ax.barh(wash_needs.index, wash_needs.values, color='#2a87c8')
ax.tick_params(axis='x', rotation=0)
# previously I used this approach to add labels
#for i, v in enumerate(wash_needs):
# ax.text(v +3, i, str(f"{v/temp:.0%}"), color='black', ha='right', va='center')
ax.bar_label(hbars, fmt='%.2f', padding=3) # this adds a label but I can't find a way to append a '%' after the number
plt.show()
我找到了一种将“%”附加到标签图形的方法-添加一个额外的“%%”
工作示例
相关问题 更多 >
编程相关推荐