Ask Your Question
0

Plot breaking the y-axis

asked 2019-04-08 11:39:57 +0200

jcarrillo gravatar image

Is there a way to force plot not to break the y-axis? For example, in this graph:

plot([12*x+23,15*x+5], (x, 0, 10), aspect_ratio=.05)
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2019-04-08 12:30:41 +0200

Juanjo gravatar image

Yes, there is a way to do so:

plot([12*x+23,15*x+5], (x, 0, 10), aspect_ratio=.05, ymax=160)

In fact, you can combine plot and show to control more precisely the window where the graph is drawn:

graph = plot([12*x+23,15*x+5], (x, 0, 10), aspect_ratio=.05)
show(graph, xmin=3, xmax=9, ymin=40, ymax=160)
edit flag offensive delete link more

Comments

This is precisely the information I needed. Thank you!

jcarrillo gravatar imagejcarrillo ( 2019-04-08 13:52:19 +0200 )edit
1

answered 2019-04-08 13:59:46 +0200

slelievre gravatar image

The two functions in the question only take values between 5 and 155, so plotchooses a corresponding y range.

There is a space between the x axis and the y axis to indicate that the y range does not start at zero. In the example from the question, it turns out that the space between the x axis and the y axis is larger than the missing part of the y axis...

I assume this is what you find puzzling, and "not to break the y-axis" means the y range should include 0 in this case.

This can be achieved here by specifying ymin=0, either in the plot:

sage: plot([12 * x + 23, 15 * x + 5], (x, 0, 10), aspect_ratio=.05, ymin=0)

or in the show:

sage: p = plot([12 * x + 23, 15 * x + 5], (x, 0, 10), aspect_ratio=.05)
sage: p.show(ymin=0)

If the graph was below 0, one would instead use ymax=0.

To not depend on whether the plot is above or below 0, add a transparent point at the origin to the plot.

sage: p = plot([12 * x + 23, 15 * x + 5], (x, 0, 10), aspect_ratio=.05)
sage: origin = point2d([(0, 0)], alpha=0)
sage: (origin + p).show()
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: 2019-04-08 11:39:57 +0200

Seen: 332 times

Last updated: Apr 08 '19