Ask Your Question
1

range() function in list_plot not working?

asked 2020-03-30 07:05:55 +0100

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!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-03-31 16:08:59 +0100

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...

edit flag offensive delete link more

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: 2020-03-30 07:05:55 +0100

Seen: 228 times

Last updated: Mar 31 '20