【发布时间】:2022-07-27 00:59:49
【问题描述】:
我想用pyplot.barh() 和ax.bar_label 在每个柱上显示柱的值。
我已阅读文档https://matplotlib.org/stable/gallery/lines_bars_and_markers/bar_label_demo.html,但没有帮助。请帮忙。
# 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)
【问题讨论】:
-
bars = plt.barh(...)和plt.bar_label(bars)? -
模块'matplotlib.pyplot'没有属性'bar_label'
-
嗯,这是一个新功能,你需要一个最新的matplotlib版本
标签: python matplotlib bar-chart