Не знаю точно, с какими проблемами вы столкнулись, поскольку вы не опубликовали пример данных.Тем не менее, ваш код делает много ненужных вещей.Вот исправленная, работающая версия:
import datetime
import matplotlib.pyplot as plt
import numpy as np
def plot_by_date(delay_list_tech):
"""plot data from delay_list_tech
input: delay_list_tech - list of dictionaries
"""
# create list of tuples
answer_list = []
for row in delay_list_tech:
x_val = row['effective_date'].split('-')
x_val_year = int(x_val[0])
x_val_mont = int(x_val[1])
x_val_day = int(x_val[2])
x_date = datetime.date(x_val_year, x_val_mont, x_val_day)
answer_list.append((x_date, row['delay_days']))
# sorting
answer_list.sort()
# error on generating array for x axis
x = np.array([row[0] for row in answer_list])
y = np.array([row[1] for row in answer_list])
plt.plot(x, y)
Тестирование:
# some test data
d = [
('1991-01-15', 47),
('1995-04-14', 10),
('1987-01-12', 99),
('2001-03-19', 41),
('1999-11-03', 9),
]
# convert to list of dictionaries, as per OP's question
d = [dict(zip(('effective_date', 'delay_days'), row)) for row in d]
# plot
plot_by_date(d)
Вывод: