ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 08 Apr 2019 13:59:46 +0200Plot breaking the y-axishttps://ask.sagemath.org/question/46045/plot-breaking-the-y-axis/ 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)
Mon, 08 Apr 2019 11:39:57 +0200https://ask.sagemath.org/question/46045/plot-breaking-the-y-axis/Answer by Juanjo for <p>Is there a way to force plot not to break the y-axis? For example, in this graph:</p>
<pre><code>plot([12*x+23,15*x+5], (x, 0, 10), aspect_ratio=.05)
</code></pre>
https://ask.sagemath.org/question/46045/plot-breaking-the-y-axis/?answer=46047#post-id-46047Yes, 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)Mon, 08 Apr 2019 12:30:41 +0200https://ask.sagemath.org/question/46045/plot-breaking-the-y-axis/?answer=46047#post-id-46047Comment by jcarrillo for <p>Yes, there is a way to do so:</p>
<pre><code>plot([12*x+23,15*x+5], (x, 0, 10), aspect_ratio=.05, ymax=160)
</code></pre>
<p>In fact, you can combine <code>plot</code> and <code>show</code> to control more precisely the window where the graph is drawn:</p>
<pre><code>graph = plot([12*x+23,15*x+5], (x, 0, 10), aspect_ratio=.05)
show(graph, xmin=3, xmax=9, ymin=40, ymax=160)
</code></pre>
https://ask.sagemath.org/question/46045/plot-breaking-the-y-axis/?comment=46049#post-id-46049This is precisely the information I needed. Thank you!Mon, 08 Apr 2019 13:52:19 +0200https://ask.sagemath.org/question/46045/plot-breaking-the-y-axis/?comment=46049#post-id-46049Answer by slelievre for <p>Is there a way to force plot not to break the y-axis? For example, in this graph:</p>
<pre><code>plot([12*x+23,15*x+5], (x, 0, 10), aspect_ratio=.05)
</code></pre>
https://ask.sagemath.org/question/46045/plot-breaking-the-y-axis/?answer=46050#post-id-46050The two functions in the question only take values between 5 and 155,
so `plot`chooses 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()
Mon, 08 Apr 2019 13:59:46 +0200https://ask.sagemath.org/question/46045/plot-breaking-the-y-axis/?answer=46050#post-id-46050