使用matplotlib bar_label标记水平条
我想用 pyplot.barh()
和 ax.bar_label
在每个栏上显示条的值。
我已经阅读了文档但这无济于事。请帮忙。
# Prepare & sort the data
df = pd.DataFrame({"coins": ["BTC", "ETH", "BNB", "XRP", "SOL", "ADA"],
"dominance": [42.08, 19.38, 3.68, 1.73, 1.55, 1.51]})
df = df.sort_values(by=["dominance"])
# Plot horizontal bar graph
plt.figure(figsize=[10, 9])
plt.barh(df.coins, df.dominance)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是
bar_label
是一项新功能,在matplotlib版本3.4或更高版本中可用 - ref this link 。使用升级到v3.4
或使用pip pip install matplotlib -upgrade
的最新版本检查Matplotlib的版本。您需要在提供的链接中以及Johanc提到的链接中包含代码,并且能够查看条标签
the issue is that the
bar_label
is a new feature and available in matplotlib version 3.4 or later - ref this link. Check the version of matplotlib usingUpgrade to
v3.4
or latest version usingpip install matplotlib --upgrade
. You will need to include the code in the link you provided and as mentioned by JohanC and be able to see bar labels