我正在尝试使用Python 2.7,matplotlib和xlwings在Excel中绘制图表。我有下面的图表,但是我只想标记年龄,而不是年龄和助手列。我怎样才能做到这一点?数据Helper Age0 91 302 273 404 455 566 447 218 459 45代码import pandas as pdimport matplotlib.pyplot as pltimport xlwings as xw# Data tabledf = pd.read_excel("test.xlsx", "Sheet2")# My workbook.wb = xw.Book('test.xlsx')# Instantiate the worksheet.sht2 = wb.sheets["Sheet2"]# Dump Age column into a dataframe.ageList = df['Age'].values.tolist()helper = df['Helper'].values.tolist()fig = plt.figure()# Line plot.plt.plot(ageList, ls = '--', color = 'red')# Label the data points here.for xy in zip(helper, ageList): plt.annotate('(%s, %s)' % xy, xy=xy, textcoords='data')sht2.pictures.add(fig, name = 'TestPlot', update = True)
1 回答
繁花不似锦
TA贡献1851条经验 获得超4个赞
仅注释要注释的值。在您的情况下,y值?
# Label the data points here.
for xy in zip(helper, ageList):
plt.annotate('(%s)' % xy[1], xy=xy, textcoords='data'
添加回答
举报
0/150
提交
取消