我正在尝试创建一个以天数为x轴和总小时数为y轴的图形,但是我不知道如何创建y轴。代码是:
hours_per_day = [1, 4, 3, 2, 3, 1]
days = [x for x in range(len(hours_per_day))]
def total_hours():
y = 0
for x in hours_per_day:
y = x + y
return y
plt.plot(days, total_hours, label="Total Hours")
错误:
ValueError: x and y must have same first dimension, but have shapes (6,) and (1,)