我有一個在不同 y 軸上帶有條形圖和折線圖的圖。我需要用它的值來標記折線圖,就在線上的每個點上方。我試過這樣的事情
for p in ax2.patches:
w,h = p.get_width(), p.get_height()
x = p.get_x()
ax2.text(x w/2, h * 1.1,
f'{h}', va='center', ha='center')
這是我用來標記條形圖的結構。我還嘗試了此頁面上列出的示例
uj5u.com熱心網友回復:
嘗試:
for x,y in t["lines"].items():
plt.annotate(f"{y:.1f}", (x,y), textcoords="offset points", xytext=(0, 5), ha="center")
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/371222.html
標籤:Python 熊猫 matplotlib
下一篇:散點圖顯示多數并包括極端數字
