# How do I use sage to plot this?

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I want to visualize graph of y = k/x (k > 0). Assume k = 10, for this example. I referred to basic command, but it's not giving me the graph as I want.

I want same scale on both axes (i.e. same length for y and x axes for 1 unit). Generally the y axis is automatically scaled, so that x pixels represent different units on y and x axes. I don't want that. I also want to have grid lines of unit squares.

edit retag close merge delete

Sort by ยป oldest newest most voted

The documentation for showing graphics has lots of options. In your case, aspect_ratio=1 will give the same scale, and gridlines and similar options control grid lines.

Actually, because k/x has an asymptote, if you really want the same scale on both axes, you'll probably want to cut off the vertical axis fairly low down. Try this example:

k = 10
plot(k/x,x,0,10,gridlines=True,aspect_ratio=1, ymax=10)


For even more control of those grid lines, read the documentation for this (search for) [xlist,ylist]: and you can pass in whatever lines you want.

 k = 10
plot(k/x,x,0,10,aspect_ratio=1, ymax=10, gridlines=[range(10),range(10)])


Or you can make the ticks different as well.

more

Thanks, aspect ratio helps! But still the gridlines are at a distance of 2 units. I wanted at a distance of 1 unit. How do I to that?

( 2014-09-08 09:58:16 -0500 )edit

I've edited my answer. The documentation is actually pretty helpful, though I agree that finding the "show" command is not at all obvious.

( 2014-09-08 10:54:47 -0500 )edit