0

Writing a code to plot a graph in python but keep getting an error.

This is my current code:

y = arange(1, 26, 1)
x = [4,1,8,6,18,2,1,7,11,0,0,1,2,9,12,2,0,5,8,13,1,2,5,0,2,0]
plot(y, x)

And the print out of what y is:

[ 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]

But i keep getting this error whenever i try and run it:

raise ValueError("x and y must have same first dimension")
ValueError: x and y must have same first dimension

What am i doing wrong :(

1 Answer 1

3

Your lists are not the same length:

>>> y
[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]
>>> x
[4, 1, 8, 6, 18, 2, 1, 7, 11, 0, 0, 1, 2, 9, 12, 2, 0, 5, 8, 13, 1, 2, 5, 0, 2, 0]
>>> len(x)
26
>>> len(y)
25

As these presumably represent a set of (x, y) points, it makes no sense to have one point with no y coordinate.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.