M.Basman M.Basman - 3 months ago 9
Python Question

Why I take slises wrong?

I have the following code:

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()


It should get data ready to build a function and actually build it. If I use "x" and "y" everything is fine but when I take "xx" and "yy" everything become wrong. For example:

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]


and I want "xx" and "yy" to be:

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


Please help me to find out what I'n doing wrong wrong.

Answer

You have typo in your code due to which logic is failing. Change yy = x[1:11] to yy = y[1:11] (i.e. x -> y) and it will work.

Comments