Ask Your Question
1

range() function in list_plot not working?

asked 5 years ago

PillarOfSand gravatar image

I'm trying to generate a list plot of points that satisfy the relation { (x,2x) | x = 0,+-1, +-2 }. That is, 5 discrete integer values of x ranging from -2 to +2 that satisfy the equation y = 2x.

I figured my solution...show(list_plot([x*2 for x in range(-2,3)]), figsize=3) should have worked; however, the resulting plot ends up shifted to the incorrect domain. I can't upload the image because my karma is too low, but the resulting plot fits the function y = 2(x - 2). It gives the correct range of y values, from -4 to 4, but the domain is from 0 to 4.

Anybody know what I'm missing? Thanks!

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 5 years ago

Juanjo gravatar image

Try

show(list_plot([(x,x*2) for x in range(-2,3)]), figsize=3)

If you don't specify the abcissae, it is assumed that they are 0, 1, 2, 3...

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 5 years ago

Seen: 302 times

Last updated: Mar 31 '20