Маркировка отдельных переменных точек в Excel с Python - PullRequest
0 голосов
/ 30 июня 2018

Я пытаюсь построить диаграмму в Excel с Python 2.7, matplotlib и xlwings. У меня есть следующий график, но я хочу пометить только Age вместо столбца Age и вспомогательного столбца.

Как я могу это сделать?

Данные

Helper  Age
0   9
1   30
2   27
3   40
4   45
5   56
6   44
7   21
8   45
9   45

Код

import pandas as pd
import matplotlib.pyplot as plt
import xlwings as xw

# Data table
df = 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)

Диаграмма

enter image description here

1 Ответ

0 голосов
/ 30 июня 2018

Только аннотируйте значение, которое вы хотите аннотировать. В вашем случае значения y?

# Label the data points here.
for xy in zip(helper, ageList):
    plt.annotate('(%s)' % xy[1], xy=xy, textcoords='data'
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...