为什么我错了?

时间:2016-08-24 08:44:37

标签: python python-2.7

我有以下代码:

counter = Counter(forgraf2.values())
dictforgraf2 = dict(counter)
x = dictforgraf2.keys() #graf2
xx = x[1:11]
print x
print xx
y = dictforgraf2.values()
yy = x[1:11]
print y
print yy
figure()
plot(xx, yy, 'r')
xlabel('days from first buy')
ylabel('number of payers')
title('days between 1 pay and last')
show()

它应该准备好数据以构建一个函数并实际构建它。如果我使用“x”和“y”一切都很好但是当我拿“xx”和“yy”时,一切都会变错。例如:

x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 120]
xx = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y = [173, 58, 47, 36, 38, 32, 20, 22, 22, 27, 12, 20, 17, 15, 15, 18, 18, 18, 10, 16, 11, 9, 10, 13, 10, 12, 12, 4, 11, 10, 14, 13, 12, 5, 7, 11, 7, 6, 8, 7, 9, 3, 7, 10, 5, 8, 9, 7, 4, 8, 9, 6, 7, 5, 6, 5, 4, 5, 5, 4, 1, 4, 2, 8, 6, 7, 4, 5, 6, 10, 8, 6, 5, 8, 1, 6, 6, 6, 5, 3, 4, 3, 3, 6, 4, 7, 2, 3, 5, 4, 6, 5, 3, 5, 1, 2, 4, 2, 1, 1, 5, 1, 3, 1, 6, 2, 3, 3, 6, 4, 5, 3, 9, 3, 3, 1, 8, 2, 6, 1]
yy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

我想要“xx”和“yy”:

xx =[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
yy =[58, 47, 36, 38, 32, 20, 22, 22, 27, 12]

请帮我弄清楚我做错了什么。

1 个答案:

答案 0 :(得分:1)

由于逻辑失败,您的代码中存在拼写错误。将yy = x[1:11]更改为yy = y[1:11](即x - > y),它会起作用。