我很難將資料標簽添加到我正在創建的 matplotlib 圖。在條形圖上我沒有問題。為了更容易地排除故障,我盡可能地簡化了它,但仍然存在同樣的問題。
我一直在無情地尋找,但找不到答案......
import matplotlib.pyplot as plt
dates = [10,11,12]
temp = [10,14,12]
temp_labels = plt.plot(dates,temp)
for x in temp_labels:
label = temp[x]
plt.annotate(label,
(x,temp[x]),
textcoords = "offset points"),
xytext = (0,10),
ha = "center")
plt.show()
我有一個錯誤:
Traceback (most recent call last):
File "rain_notif.py", line 16, in <module>
label = temp[x]
TypeError: list indices must be intergers or slices, not Line2D
這是我所擁有的,我只想在每個點的頂部重視標簽。

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/357838.html
標籤:Python matplotlib 图形 标签
上一篇:圖未顯示在Jupyter實驗室中
