[英]How do you add (x,y) labels to a pandas matplotlib figure?
So I have a plot but I do not get how to add data labels to my figures.所以我有一个情节,但我不知道如何为我的数字添加数据标签。 I get the desired plots but I would like to see the y-value for each point.
我得到了想要的图,但我想查看每个点的 y 值。 Here is the code:
这是代码:
list_of_centers=os.listdir("./")
for i in range(len(list_of_centers)):
xls = pd.ExcelFile("./"+list_of_centers[i])
for j in range(len(xls.sheet_names)):
df=pd.read_excel("./"+list_of_centers[i])
df=df.drop(columns=['Y', 'C','O','Y_C','Y_O'])
df=df.set_index('Date')
lines = df.plot.line(title=list_of_centers[i][:-5]+"_"+xls.sheet_names[j])
#add labels
plt.savefig("./"+list_of_centers[i]
[:-5]+"_"+xls.sheet_names[j]+".png")
You can try the following, just add it under #add labels
(Also see: Add x and y labels to a pandas plot )您可以尝试以下操作,只需将其添加到
#add labels
(另请参阅: 将 x 和 y 标签添加到熊猫图)
lines.set_xlabel("x label")
lines.set_ylabel("y label")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.